LoadViewState not called in custom control

B

Brad

A custom control I have created overrides LoadViewState and SaveViewState.
Problem is that my override of LoadViewState is not getting called: debugger
breakpoint is not stopping at in it. The control is similar to panel
control, it allows child controls to be added within it: so
ParseChildren(False) and PersistChildren(True). Is there a limitation on
LoadViewState when ParseChildern and PersistChildren are set as I have?
Except for this problem the control works correctly.

Brad
 
S

Steven Cheng[MSFT]

Hi Brad,

Thanks for posting here. Regarding on this issue, I'll first do some tests
on my side and I'll let you know my result as soon as possible. In
addition, if you got any other finding during the time, please also feel
free to post here. Thanks.

Regards,

Steven Cheng
Microsoft Online Support

Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)
 
B

Brad

I should also mention I do also override Trackviewstate. I know
Trackviewstate executes before Loadviewstate....and as best I can tell
adding my code to Trackviewstate will work. But I'd still like to know how
to properly get my Loadviewstate override to execute....if it will with a
panel type control..

Brad
 
S

Steven Cheng[MSFT]

Hi Brad,

Thanks for your followup. I've done a simple test on my side. Creating a
webcontrol which applys the
"ParseChildren(false)" and "PersistChildren(true)", but seems the
LoadViewState and SaveViewState override methods still be entered. Here is
the test control's code, you may also have a try to see whether the result
on your side is the same, if so , I think we should focus on the particular
control which suffering the problem:

=====================
[DefaultProperty("Text"), ParseChildren(false), PersistChildren(true),
ToolboxData("<{0}:SimplePanel runat=server></{0}:SimplePanel>")]
public class SimplePanel :
System.Web.UI.WebControls.WebControl,INamingContainer
{
private string text;
private string _controlname;


public string ControlName
{
get
{
return _controlname;
}
set
{
_controlname = value;
}
}

[Bindable(true),
Category("Appearance"),
DefaultValue("")]
public string Text
{
get
{
return text;
}

set
{
text = value;
}
}

protected override void LoadViewState(object savedState)
{
Triplet tpt = savedState as Triplet;
_controlname = tpt.First as string;
base.LoadViewState (tpt.Second);
}

protected override object SaveViewState()
{
Triplet tpt = new Triplet(_controlname,base.SaveViewState ());
return tpt;
}

protected override void Render(HtmlTextWriter writer)
{
base.Render (writer);
writer.WriteLine("<br>ControlName: " + this.ControlName);
}
}
======================

If you have any other questions or finding, please also feel free to post
here. Thanks.

Regards,

Steven Cheng
Microsoft Online Support

Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)
 
S

Steven Cheng[MSFT]

Hi Brad,

Have you got any further progress on this issue or have you got it
resolved? If there're anything else we can help, please feel free to post
here. Thanks.

Regards,

Steven Cheng
Microsoft Online Support

Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)
 
B

Brian Noyes

I'm having the same problem with LoadViewState and SaveViewState not
being called. I cut and pasted the code from your SimplePanel into a
WebControl library and tried adding it to the page.

The LoadViewState and SaveViewState methods never get called as
evidenced by setting breakpoints in them in the debugger, and also if I
change the ControlName property in the Load event handler only when not
postback, it is apparent that the value is not being persisted through
viewstate.
 
B

Brian Noyes

Disregard my previous post. The problem was that some knucklehead had
slapped a web.config file in the root folder for the site that contained
EnableViewState="false", so naturally the viewstate methods were not
being called.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,579
Members
45,053
Latest member
BrodieSola

Latest Threads

Top