總體思路ASP:在兩個ScriptManager之間切換。以及如何刪除腳本參考
我總的想法是讓我的網站的移動和桌面版本。用戶可以使用頁面底部的按鈕切換版本。我使用ASP主題,以便根據所需的網站版本輕鬆切換主題。
問題
切換主題是偉大的,但因爲我有JavaScript
文件已經包含在我的項目在我的母版頁以下ScriptManager
:
<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>
當用戶切換到桌面版本有jquery.mobile-1.3.1.min.js
和jQueryMobileBehaviour.js
引起的問題。有沒有辦法使用兩個ScriptManagers(某種主題,但爲js文件)?
我已經嘗試沒有成功
我的第一種方法是從ScriptManager
刪除移動JavaScript
文件,然後手動將它們包括在按鈕的點擊事件切換到移動版那樣sm.Scripts.Add
。
第二種方法是以編程方式刪除像sm.Scripts.Remove
這樣的移動JavaScript
文件。
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);
}
這兩種方法都不起作用。
要總結問題
- 有什麼錯在我的代碼 - 假設路徑應該是好嗎?
- 是否有更好的方法,這將允許我切換
JavaScript
文件,就像完成主題一樣?
也許如果你添加兩個''有兩個不同的設置和兩個不同的ID,並且你將它們交換(一個可見,一個隱藏)。 –
Aristos
@Aristos我無法在一個頁面上添加兩個ScriptManager。我目前正在尋找解決方法,但如果您知道如何添加多個ScriptManager,請告訴我。 –
@Aristos感謝您的幫助,我設法解決了我的問題。我在下面添加了我的解決方案。 –