ConfusedCoder
ConfusedCoder

Reputation: 175

How to load .ascx control in .aspx page with out postback or reloading the page

I have some code that is running fine , what i want is when i create a cookie i want the .ascx control to load to perform some function on the cookie but i don't want the page to post back, how can i achieve that.

Upvotes: 1

Views: 3352

Answers (2)

ConfusedCoder
ConfusedCoder

Reputation: 175

Well i found a more simpler way how to just load the .ascx control without postback

Just put the .ascx control in a update panel and reload the update panel only using this..

   function  addCookies(typeShopping,id,name,price) {

       document.cookie = typeShopping + "=" + id + "," + name + "," + price;

       __doPostBack('<%=UpdatePanel2.ClientID %>', 'addTocart');
    }

And as you can see we can pass parameters to the control or just write NULL. And i place the control in the update panel like this....

    <asp:ScriptManager ID="ScriptManager1" runat="server">

    </asp:ScriptManager> 

    <asp:UpdatePanel ID="UpdatePanel2" runat="server">
               <ContentTemplate>
                   <uc1:Basket ID="Basket1" runat="server"  />  
             </ContentTemplate>
            </asp:UpdatePanel>

This works absolutely perfect for me i don't know if there is any drawback using this concept.

Upvotes: 0

Paul
Paul

Reputation: 36339

You can use a page WebMethod or a WebService to load the html from the ascx and serve it to your javascript. There's a tutorial here for doing it.

Upvotes: 3

Related Questions