Dynamically changing themes in asp.net
Themes are styling objects in asp.net. We can set the themes by using Theme page directive or by adding or modifing <pages theme=”" /> tag Web.config.
But if you want to change it in run-time you need to set the theme in the Page_PreInit event in the ASP.Net Page Life-Cycle.
Simple implementation of changing theme in dynamically in asp.net
In this there is a dropdown list which displays all the theme / skin files in the current application, with autopostback enabled.
Page_Load event
protected void Page_Load(object sender, EventArgs e)
{
if (!Page.IsPostBack)
{
foreach (string dir in Directory.GetDirectories(Request.MapPath("./App_Themes")))
{
this.ThemeSelector.Items.Add(new ListItem(Path.GetFileNameWithoutExtension(dir), Path.GetFileNameWithoutExtension(dir)));
}
this.ThemeSelector.Items.Insert(0, new ListItem("-- SELECT --", "-1"));
}
}
Dropdown selected Index change Event
protected void ThemeSelector_SelectedIndexChanged(object sender, EventArgs e)
{
if (this.ThemeSelector.SelectedValue != "-1")
{
Session["theme"] = this.ThemeSelector.SelectedValue;
}
}
Page_PreInit event
protected void Page_PreInit(object sender, EventArgs e)
{
if (Session["theme"] != null)
{
this.Theme = Session["theme"] as string;
}
}
The selected theme is storing into a session variable in selected Index change event and in the Page preinit event it is setting as the current page’s theme. This can be applied to all the pages in a web application, because we are using Session variable.
"CS1010: Newline in Constant" Error Message When a String Contains a Tag in the Inline Code
While working in ASP.Net and Java-script, we often use strings or string builder objects to register client script into the page. And when it comes to writing </script> tag, ASP.Net throws “CS1010: Newline in Constant” Error. The workaround for this problem is split the </SCRIPT> tag in to two strings, such as “<” + “/script>”.
The same can be found from MSDN support center (url : http://support.microsoft.com/kb/827420)
Validation groups
Today while developing a webpart for my sharepoint project, I noticed that one of my webpart’s validators firing, while modifying webpart properties. Initially I was looked for some tricky solutions, where I can disable the webpart validators. But after a few moments I come to know about ASP.Net new validation group property. I modified the code with a new validation group. And now it is working fine.
Displaying ASP.Net error pages in WSS
Normally while developing applications in WSS, if any error occured, the WSS will give it’s own error page, and it contains nothing much information about the error, like unexpected error occured. To enable to view the ASP.Net error page we need to modify the web.config in the Root directory. Change the customErrors mode from “On” to “Off” or “RemoteOnly”. And change the CallStack attribute of SafeMode tag from “false” to “true”. Then if an error occurs it WSS will give the exact error.
"Object reference" error while deploying webpart using VS 2005
Today, while deploying webpart to our WSS 3.0 server we got some funny errors like object reference not set to an instance of an object. The team got stuck in there for more than 3 hours. After lot of googling we found it is because of missing some entries in the WSS Content Database. To fix this issue, Microsoft doesn’t providing any tool. And we got some tools and tips from
And we found the FeatureCleaner v0 is good tool, compare to Missing Feature.exe, because in the latter we need to give the Connection string to the WSS Database.
Update
We need to modify the FeatureCleaner v0 source, if you WSS installed on other than C:\ Drive.