G
Grant Merwitz
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(object sender, System.EventArgs e)
{
if(!Page.IsPostBack)
{
Switch(Request.Params["P"])
{
case "1" :
Control uc = LoadControl("/controls/control1.ascx");
pnlContent.Controls.Add(uc);
break;
case "2" :
Control uc = LoadControl("/controls/control2.ascx");
pnlContent.Controls.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_ascx' must be marked as Serializable or have a
TypeConverter other than ReferenceConverter 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(object sender, System.EventArgs e)
{
if(!Page.IsPostBack)
{
Switch(Request.Params["P"])
{
case "1" :
Control uc = LoadControl("/controls/control1.ascx");
pnlContent.Controls.Add(uc);
break;
case "2" :
Control uc = LoadControl("/controls/control2.ascx");
pnlContent.Controls.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_ascx' must be marked as Serializable or have a
TypeConverter other than ReferenceConverter 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.