General idea
My general idea is to have mobile and desktop version of my site. Users can switch versions with buttons on the bottom of the page. I'm using ASP themes, so that I can easily switch themes depending on the required version of the site.
The problem
Switching themes is great, but since I've got JavaScript files already included in my project in the following ScriptManager in my master page:
<asp:ScriptManager runat="server" ID="sm">
<Scripts>
<asp:ScriptReference Path="~/Scripts/jquery-2.0.2.min.js" />
<asp:ScriptReference Path="~/Scripts/jQueryMobileBehaviour.js" />
<asp:ScriptReference Path="~/Scripts/Master.js" />
<asp:ScriptReference Path="~/Scripts/jquery.mobile-1.3.1.min.js" />
</Scripts>
</asp:ScriptManager>
When the user switch to desktop version there are problems caused by jquery.mobile-1.3.1.min.js and jQueryMobileBehaviour.js. Is there a way to use two ScriptManagers (some sort of themes but for js files)?
What I've tried without success
My first approach was to remove the mobile JavaScript files from the ScriptManager and then include them manually in the click event of the button that switches to mobile version like that sm.Scripts.Add.
The second approach was to remove programmatically the mobile JavaScript files like that sm.Scripts.Remove.
protected void CommandBtn_Click(Object sender, CommandEventArgs e)
{
switch (e.CommandName)
{
case "Desktop":
HttpContext.Current.Response.Cookies["theme"].Value = "Desktop";
//sm.Scripts.Remove(new ScriptReference("~/Scripts/jquery.mobile-1.3.1.min.js"));
break;
case "Mobile":
HttpContext.Current.Response.Cookies["theme"].Value = "Mobile";
//sm.Scripts.Add(new ScriptReference("~/Scripts/jquery-2.0.2.min.js"));
//Response.Redirect(Request.RawUrl);
break;
default:
break;
}
Page.Response.Redirect(Page.Request.Url.ToString(), true);
}
Both approaches didn't work.
To sum up the questions
- Is there something wrong in my code - assuming that the paths should be alright?
- Is there a better approach, which will allow me to switch
JavaScriptfiles, like is done with the themes?
<asp:ScriptManager runat="server" ID="sm">with two different setup and two different ids, and you swap them (one visible, one hidden) base on your them.