I am using usercontrols to control the contant in my website.
Currently, depending on a parameter passed in the querystring, the
appropriate usercontrol will be loaded.
i.e.
private void Page_Load(objec t sender, System.EventArg s e)
{
if(!Page.IsPost Back)
{
Switch(Request. Params["P"])
{
case "1" :
Control uc = LoadControl("/controls/control1.ascx") ;
pnlContent.Cont rols.Add(uc);
break;
case "2" :
Control uc = LoadControl("/controls/control2.ascx") ;
pnlContent.Cont rols.Add(uc);
break;
}
}
}
But now, when one of these control calls an internal method, the page posts
back and the control disappears.
I understand this i because the control is loaded through the code and is
not loaded again in the postback.
I have solved this problem by keeping the control in a session during post
backs, but am not completely sure if this is the right way to do things.
I have also tried to viewstate the control, but get the error:
The type 'ASP.control1_a scx' must be marked as Serializable or have a
TypeConverter other than ReferenceConver ter to be put in viewstate.
I have further tried to mark the control as Serializable which didn't seem
to help.
Can anyone suggest a better way of doing this, or a solution
Thanks
Grant
P.S. the control is not called control1.ascx, i just renamed it for this
example.
Currently, depending on a parameter passed in the querystring, the
appropriate usercontrol will be loaded.
i.e.
private void Page_Load(objec t sender, System.EventArg s e)
{
if(!Page.IsPost Back)
{
Switch(Request. Params["P"])
{
case "1" :
Control uc = LoadControl("/controls/control1.ascx") ;
pnlContent.Cont rols.Add(uc);
break;
case "2" :
Control uc = LoadControl("/controls/control2.ascx") ;
pnlContent.Cont rols.Add(uc);
break;
}
}
}
But now, when one of these control calls an internal method, the page posts
back and the control disappears.
I understand this i because the control is loaded through the code and is
not loaded again in the postback.
I have solved this problem by keeping the control in a session during post
backs, but am not completely sure if this is the right way to do things.
I have also tried to viewstate the control, but get the error:
The type 'ASP.control1_a scx' must be marked as Serializable or have a
TypeConverter other than ReferenceConver ter to be put in viewstate.
I have further tried to mark the control as Serializable which didn't seem
to help.
Can anyone suggest a better way of doing this, or a solution
Thanks
Grant
P.S. the control is not called control1.ascx, i just renamed it for this
example.
Comment