473,804 Members | 3,797 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

View state problem

The code snippets are below.

I write in (C#) a Page object in a control library.
I'm using this page as an HtppHandler in a website (which referes the DLL).
This page contains 2 panels (one is visible when the other is not).
When I postback to the page (httphandler) the viewstate is apparently incorrectly restored, that is my 2 panels get visible=false (that is only 1 should be invisible) for no reason I could understand.

Any idea of why is that?

PS: I checked the page, there is a viewstate field with some value... which changes between queries...
===== code in the consumer web site =======

=== IGallery.ashx ==
<%@ WebHandler Language="C#" Class="IGallery " %>

using System;
using System.Web;

using WebUtils;

public class IGallery : FTBImageGallery
{
}

===== code of the WebUtils control library ==========

=== FTBImageGallery .cs ===
namespace WebUtils
{
public class FTBImageGallery : CodePage
{
public override void ProcessRequest( HttpContext context)
{
string imageId = context.Request["getimage"];
if (string.IsNullO rEmpty(imageId) )
{
base.ProcessReq uest(context);
return;
}
WriteImage(cont ext, imageId);
}

Panel pUpload, pSelect;
protected override void CreateChildCont rols()
{
base.CreateChil dControls();
MainForm.Contro ls.Add(pUpload = CreateUploadPan el());
MainForm.Contro ls.Add(pSelect = CreateSelectPan el());
pUpload.Visible = false;
}
Panel CreateSelectPan el()
{
Panel p = new Panel();
p.ID = "select";
// ......
return p;
}
Panel CreateUploadPan el()
{
Panel p = new Panel();
p.ID = "upload";
// ......
return p;
}
}
}

=== CodePage.cs ===
namespace WebUtils
{
public class CodePage : Page
{
public bool ValidateRequest = false;

protected override void FrameworkInitia lize()
{
base.FrameworkI nitialize();
InitializeCultu re();
BuildPage();
Title = Title;
if(ValidateRequ est)
Request.Validat eInput();
}

public readonly HtmlForm MainForm = new HtmlForm();
public readonly HtmlHead Head = new HtmlHead();
HtmlTitle pageTitle = new HtmlTitle();
public readonly HtmlGenericCont rol Body = new HtmlGenericCont rol("body");

public new string Title
{
get { return base.Title; }
set
{
pageTitle.Text = value;
base.Title = value;
}
}

protected virtual void BuildPage()
{
Head.Controls.A dd(pageTitle);
Body.Controls.A dd(MainForm);
MainForm.Contro ls.Add(new LiteralControl( "\r\n"));

Controls.Add(ne w LiteralControl( "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Transitional//EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dt d\">\r\n<html xmlns=\"http://www.w3.org/1999/xhtml\" >\r\n"));
Controls.Add(He ad);
Controls.Add(ne w LiteralControl( "\r\n"));
Controls.Add(Bo dy);
Controls.Add(ne w LiteralControl( "\r\n</html>\r\n"));
}
}
}

=============== =============== ===
--
I have taken a vow of poverty. If you want to really piss me off, send me money.

Jan 19 '06 #1
4 1796
The problem seems to be triggered by a LinkButton I have on the page in fact.
it has the following reasonable looking code:

LinkButton linkSelectUploa d;
protected override void CreateChildCont rols()
{
base.CreateChil dControls();

linkSelectUploa d = new LinkButton();
linkSelectUploa d.Text = "Upload Images";
linkSelectUploa d.Click += HSwitchSelectUp load;
MainForm.Contro ls.Add(linkSele ctUpload);

MainForm.Contro ls.Add(pUpload = CreateUploadPan el());
MainForm.Contro ls.Add(pSelect = CreateSelectPan el());
pUpload.Visible = false;
}
void HSwitchSelectUp load(object sender, EventArgs e)
{
pUpload.Visible = !pUpload.Visibl e;
pSelect.Visible = !pSelect.Visibl e;
linkSelectUploa d.Text = pUpload.Visible ? "Select Image" : "Upload Images";
}
"Lloyd Dupont" <net.galador@ld > wrote in message news:%2******** ********@TK2MSF TNGP14.phx.gbl. ..
The code snippets are below.

I write in (C#) a Page object in a control library.
I'm using this page as an HtppHandler in a website (which referes the DLL).
This page contains 2 panels (one is visible when the other is not).
When I postback to the page (httphandler) the viewstate is apparently incorrectly restored, that is my 2 panels get visible=false (that is only 1 should be invisible) for no reason I could understand.

Any idea of why is that?

PS: I checked the page, there is a viewstate field with some value... which changes between queries...
===== code in the consumer web site =======

=== IGallery.ashx ==
<%@ WebHandler Language="C#" Class="IGallery " %>

using System;
using System.Web;

using WebUtils;

public class IGallery : FTBImageGallery
{
}

===== code of the WebUtils control library ==========

=== FTBImageGallery .cs ===
namespace WebUtils
{
public class FTBImageGallery : CodePage
{
public override void ProcessRequest( HttpContext context)
{
string imageId = context.Request["getimage"];
if (string.IsNullO rEmpty(imageId) )
{
base.ProcessReq uest(context);
return;
}
WriteImage(cont ext, imageId);
}

Panel pUpload, pSelect;
protected override void CreateChildCont rols()
{
base.CreateChil dControls();
MainForm.Contro ls.Add(pUpload = CreateUploadPan el());
MainForm.Contro ls.Add(pSelect = CreateSelectPan el());
pUpload.Visible = false;
}
Panel CreateSelectPan el()
{
Panel p = new Panel();
p.ID = "select";
// ......
return p;
}
Panel CreateUploadPan el()
{
Panel p = new Panel();
p.ID = "upload";
// ......
return p;
}
}
}

=== CodePage.cs ===
namespace WebUtils
{
public class CodePage : Page
{
public bool ValidateRequest = false;

protected override void FrameworkInitia lize()
{
base.FrameworkI nitialize();
InitializeCultu re();
BuildPage();
Title = Title;
if(ValidateRequ est)
Request.Validat eInput();
}

public readonly HtmlForm MainForm = new HtmlForm();
public readonly HtmlHead Head = new HtmlHead();
HtmlTitle pageTitle = new HtmlTitle();
public readonly HtmlGenericCont rol Body = new HtmlGenericCont rol("body");

public new string Title
{
get { return base.Title; }
set
{
pageTitle.Text = value;
base.Title = value;
}
}

protected virtual void BuildPage()
{
Head.Controls.A dd(pageTitle);
Body.Controls.A dd(MainForm);
MainForm.Contro ls.Add(new LiteralControl( "\r\n"));

Controls.Add(ne w LiteralControl( "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Transitional//EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dt d\">\r\n<html xmlns=\"http://www.w3.org/1999/xhtml\" >\r\n"));
Controls.Add(He ad);
Controls.Add(ne w LiteralControl( "\r\n"));
Controls.Add(Bo dy);
Controls.Add(ne w LiteralControl( "\r\n</html>\r\n"));
}
}
}

=============== =============== ===
--
I have taken a vow of poverty. If you want to really piss me off, send me money.

Jan 19 '06 #2
Haha..
There are some HtmlInputFile which seems to be the cause of the disappearance of the ViewState...
Any idea why?
"Lloyd Dupont" <net.galador@ld > wrote in message news:%2******** ********@TK2MSF TNGP14.phx.gbl. ..
The code snippets are below.

I write in (C#) a Page object in a control library.
I'm using this page as an HtppHandler in a website (which referes the DLL).
This page contains 2 panels (one is visible when the other is not).
When I postback to the page (httphandler) the viewstate is apparently incorrectly restored, that is my 2 panels get visible=false (that is only 1 should be invisible) for no reason I could understand.

Any idea of why is that?

PS: I checked the page, there is a viewstate field with some value... which changes between queries...
===== code in the consumer web site =======

=== IGallery.ashx ==
<%@ WebHandler Language="C#" Class="IGallery " %>

using System;
using System.Web;

using WebUtils;

public class IGallery : FTBImageGallery
{
}

===== code of the WebUtils control library ==========

=== FTBImageGallery .cs ===
namespace WebUtils
{
public class FTBImageGallery : CodePage
{
public override void ProcessRequest( HttpContext context)
{
string imageId = context.Request["getimage"];
if (string.IsNullO rEmpty(imageId) )
{
base.ProcessReq uest(context);
return;
}
WriteImage(cont ext, imageId);
}

Panel pUpload, pSelect;
protected override void CreateChildCont rols()
{
base.CreateChil dControls();
MainForm.Contro ls.Add(pUpload = CreateUploadPan el());
MainForm.Contro ls.Add(pSelect = CreateSelectPan el());
pUpload.Visible = false;
}
Panel CreateSelectPan el()
{
Panel p = new Panel();
p.ID = "select";
// ......
return p;
}
Panel CreateUploadPan el()
{
Panel p = new Panel();
p.ID = "upload";
// ......
return p;
}
}
}

=== CodePage.cs ===
namespace WebUtils
{
public class CodePage : Page
{
public bool ValidateRequest = false;

protected override void FrameworkInitia lize()
{
base.FrameworkI nitialize();
InitializeCultu re();
BuildPage();
Title = Title;
if(ValidateRequ est)
Request.Validat eInput();
}

public readonly HtmlForm MainForm = new HtmlForm();
public readonly HtmlHead Head = new HtmlHead();
HtmlTitle pageTitle = new HtmlTitle();
public readonly HtmlGenericCont rol Body = new HtmlGenericCont rol("body");

public new string Title
{
get { return base.Title; }
set
{
pageTitle.Text = value;
base.Title = value;
}
}

protected virtual void BuildPage()
{
Head.Controls.A dd(pageTitle);
Body.Controls.A dd(MainForm);
MainForm.Contro ls.Add(new LiteralControl( "\r\n"));

Controls.Add(ne w LiteralControl( "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Transitional//EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dt d\">\r\n<html xmlns=\"http://www.w3.org/1999/xhtml\" >\r\n"));
Controls.Add(He ad);
Controls.Add(ne w LiteralControl( "\r\n"));
Controls.Add(Bo dy);
Controls.Add(ne w LiteralControl( "\r\n</html>\r\n"));
}
}
}

=============== =============== ===
--
I have taken a vow of poverty. If you want to really piss me off, send me money.

Jan 19 '06 #3
Solved!!!

It probably has to do as to when the view state is applied.
If I set panel.Visible = false before adding it to the page, it works!
"Lloyd Dupont" <net.galador@ld > wrote in message news:%2******** ********@TK2MSF TNGP14.phx.gbl. ..
The code snippets are below.

I write in (C#) a Page object in a control library.
I'm using this page as an HtppHandler in a website (which referes the DLL).
This page contains 2 panels (one is visible when the other is not).
When I postback to the page (httphandler) the viewstate is apparently incorrectly restored, that is my 2 panels get visible=false (that is only 1 should be invisible) for no reason I could understand.

Any idea of why is that?

PS: I checked the page, there is a viewstate field with some value... which changes between queries...
===== code in the consumer web site =======

=== IGallery.ashx ==
<%@ WebHandler Language="C#" Class="IGallery " %>

using System;
using System.Web;

using WebUtils;

public class IGallery : FTBImageGallery
{
}

===== code of the WebUtils control library ==========

=== FTBImageGallery .cs ===
namespace WebUtils
{
public class FTBImageGallery : CodePage
{
public override void ProcessRequest( HttpContext context)
{
string imageId = context.Request["getimage"];
if (string.IsNullO rEmpty(imageId) )
{
base.ProcessReq uest(context);
return;
}
WriteImage(cont ext, imageId);
}

Panel pUpload, pSelect;
protected override void CreateChildCont rols()
{
base.CreateChil dControls();
MainForm.Contro ls.Add(pUpload = CreateUploadPan el());
MainForm.Contro ls.Add(pSelect = CreateSelectPan el());
pUpload.Visible = false;
}
Panel CreateSelectPan el()
{
Panel p = new Panel();
p.ID = "select";
// ......
return p;
}
Panel CreateUploadPan el()
{
Panel p = new Panel();
p.ID = "upload";
// ......
return p;
}
}
}

=== CodePage.cs ===
namespace WebUtils
{
public class CodePage : Page
{
public bool ValidateRequest = false;

protected override void FrameworkInitia lize()
{
base.FrameworkI nitialize();
InitializeCultu re();
BuildPage();
Title = Title;
if(ValidateRequ est)
Request.Validat eInput();
}

public readonly HtmlForm MainForm = new HtmlForm();
public readonly HtmlHead Head = new HtmlHead();
HtmlTitle pageTitle = new HtmlTitle();
public readonly HtmlGenericCont rol Body = new HtmlGenericCont rol("body");

public new string Title
{
get { return base.Title; }
set
{
pageTitle.Text = value;
base.Title = value;
}
}

protected virtual void BuildPage()
{
Head.Controls.A dd(pageTitle);
Body.Controls.A dd(MainForm);
MainForm.Contro ls.Add(new LiteralControl( "\r\n"));

Controls.Add(ne w LiteralControl( "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Transitional//EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dt d\">\r\n<html xmlns=\"http://www.w3.org/1999/xhtml\" >\r\n"));
Controls.Add(He ad);
Controls.Add(ne w LiteralControl( "\r\n"));
Controls.Add(Bo dy);
Controls.Add(ne w LiteralControl( "\r\n</html>\r\n"));
}
}
}

=============== =============== ===
--
I have taken a vow of poverty. If you want to really piss me off, send me money.

Jan 19 '06 #4
sam
Yeah, I know why this is.

You have to know about the LoadViewState event. See this page:
http://www.15seconds.com/issue/020102.htm

Basically, what you *were* doing in overriding the restored view state
value by setting visibility = false *after* the viewstate was restored
properly. So pUpload visibility was always being restored properly by
viewstate, but you were always setting it to false right after that
(LoadViewState event occurs when you add pUpload to the Controls
collection - controls play catchup on lifecycle events when added to a
preexisting control tree). But when you set it to false *before*
adding it to the controls collection you gave a chance for viewstate to
be restored to it properly, since you stopped overriding it right after
that.

Make sense? Basically this ASP.NET stuff is a lot more complicated
than a lot of ppl say it is ;).

-Sam

Jan 19 '06 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
1589
by: Bren | last post by:
I am developing a web based app. in .net, with C# as the code behind.the problem I am having is with view state for a page. the page is capturing an event fired in an object. the event changes the properties of various controls in the UI. the event is fired when the user enters some info. on the page, initiating a post back etc. However, when i test the page, the changes that should appear in the UI don't happen. debugging through the code...
0
1104
by: Bren | last post by:
I am developing a web based app. in .net, with C# as the code behind.the problem I am having is with view state for a page. the page is capturing an event fired in an object. the event changes the properties of various controls in the UI. the event is fired when the user enters some info. on the page, initiating a post back etc. However, when i test the page, the changes that should appear in the UI don't happen. debugging through the code...
0
312
by: Eran Amitai | last post by:
I have the simplest web page (using code-behind): <body> <%# MyText %> two buttons - button1 and button2 </body> My code-behind web page is very simple too: public class WebForm3 : System.Web.UI.Page { protected System.Web.UI.WebControls.Button Button2;
2
3222
by: Vinod I | last post by:
Hi Team, When I tryed following code, I am getting the Runtime Error as "The View State is invalid for this page and might be corrupted." Exception Details: System.Web.HttpException: The View State is invalid for this page and might be corrupted. Stack Trace: System.Web.UI.Page.LoadPageStateFromPersistenceMedium() +150 System.Web.UI.Page.LoadPageViewState() +16
2
783
by: Brad | last post by:
I have an intranet app that has just started sporadically getting the following error "The viewstate is invalid for this page and might be corrupted." By sproadic I mean 3-4 times during the past two days out of 100's of hits. The error just started yesterday and this app has been running for quite some time without this error and has not been updated just before or after the error started. Reseaching this error I've checked the...
3
2127
by: Philip Tripp | last post by:
I've read numerous sources stating that view state can be disabled per control, and per page, but can't seem to keep web form controls from remembering their state on a postback. I'm using VS.Net 2002, .Net Framework 1.0 SP2. I create a new project, and add a new web form to the project. On the page properties, I set EnableViewState to False and verify that the @ Page directive has "enableViewState=false" in it. I then add a TextBox...
2
2914
by: Chad | last post by:
I have a problem that I am desperate to understand. It involves dynamically adding controls to a Table control that is built as a result of performing a database query. I am not looking to avoid the problem by avoiding the table control or resorting to databound controls that better manage state for me. I hope to understand how to solve the problem by using the Table web control and sticking to the approach of building the table at run...
2
1851
by: Hope Paka | last post by:
My web page, has an average of 1500 hits every day. Every day, i get invalid view state exception, average of 10 times. The exception message in at the bottom. When i try to parse the view state in the exception message, it is really not well formatted. I do not think that, my customers, change the view state, and try to post it. Somethign that i don't know is happening at the backend? Could somebody have had the same problem.?...
1
1882
by: Ken Varn | last post by:
I have a problem where my DataGrid would not maintain the ViewState of my databound rows. I finally narrowed down the problem. If my first column is a template column, the view state for the DataGrid items is not maintained on postback for some reason. I basically re-created my DataGrid again just to make sure this was indeed the problem. The ViewState was fine until I added the template column at the beginning of the Columns list. ...
1
5185
by: =?Utf-8?B?Tmls?= | last post by:
Hi, I am facing problem with the huge Viewstate size(Using .NET 2.0). to improve the application performance, I am using Static variable to store view state data. Does anyone has other option to improve performance or what r drawback of using Static variable. Thanks, Nil
0
9708
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9588
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10589
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10340
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
7625
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5527
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5663
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4302
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
2999
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.