![](/img/trans.png)
[英]SET Parent page (aspx) label text from User Control (ascx) using JavaScript and without PostBack()
[英]How to load .ascx control in .aspx page with out postback or reloading the page
我有一些運行良好的代碼,我想要的是當我創建一個 cookie 時,我希望加載 .ascx 控件以在 cookie 上執行一些 function 但我不希望頁面回發,我該如何實現.
您可以使用頁面 WebMethod 或 WebService 從 ascx 加載 html 並將其提供給您的 javascript。 這里有一個教程可以做到這一點。
好吧,我找到了一種更簡單的方法,如何在不回發的情況下加載.ascx 控件
只需將 .ascx 控件放在更新面板中,然后僅使用它重新加載更新面板..
function addCookies(typeShopping,id,name,price) {
document.cookie = typeShopping + "=" + id + "," + name + "," + price;
__doPostBack('<%=UpdatePanel2.ClientID %>', 'addTocart');
}
如您所見,我們可以將參數傳遞給控件,或者只編寫 NULL。 我像這樣將控件放在更新面板中....
<asp:ScriptManager ID="ScriptManager1" runat="server">
</asp:ScriptManager>
<asp:UpdatePanel ID="UpdatePanel2" runat="server">
<ContentTemplate>
<uc1:Basket ID="Basket1" runat="server" />
</ContentTemplate>
</asp:UpdatePanel>
這對我來說絕對完美,我不知道使用這個概念是否有任何缺點。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.