How to change a controls SkinID at runtime (asp.net 2.0)

S

stephen.mcallister

I am toying around with Personalization in asp.net 2.0 and would like
my users to be able to choose a SkinID at runtime.
I have a theme with a default gridview skin and a custom skin.
There are 2 buttons on a Control that I was hoping I could use to
switch the SkinID, but it appears it's not that easy to do during
runtime.

Here is the code I tried to use

protected void imgBtnDefaultColour_Click(object sender,
ImageClickEventArgs e)
{

gvReqListing.SkinID = "";

}
protected void imgBtnSecondColour_Click(object sender,
ImageClickEventArgs e)
{
gvReqListing.SkinID = "gvWebPart";

}

and the error message that I received

The 'SkinId' property cannot be changed dynamically if Page has a
stylesheet theme. For dynamic controls, set the property before calling
ApplyStyleSheetSkin().

Any help or suggestions would be greatly appreciated.
 
Joined
Apr 12, 2008
Messages
1
Reaction score
0
Change theme at runtime (asp.net 2.0)

you use session to save your setting, after that redirect site,like this:
protected void rad1_SelectedIndexChanged(object sender, EventArgs e)//rad1 is radioButtonList
{
Session["themesPage"] = rad1.SelectedValue;
Server.Transfer(Request.Path);
}

at method Page_PreInit, you use:
protected void Page_PreInit(object sender, EventArgs e)
{
string thm;
thm = (string)Session["themesPage"];
if (thm != null && thm != string.Empty)
{
Page.Theme = thm;//name theme
rad1.SelectedValue = thm;
}
else
{
Session["themesPage"] = rad1.SelectedValue;
Page.Theme = "theme1";//name theme
}


Good luck :driver:
 
Last edited:

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

No members online now.

Forum statistics

Threads
473,743
Messages
2,569,478
Members
44,899
Latest member
RodneyMcAu

Latest Threads

Top