Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C# ASP.NET
I know this has been asked too much and there are these on the net:
http://encosia.com/using-jquery-to-directly-call-aspnet-ajax-page-methods/[^]
http://encosia.com/using-jquery-to-consume-aspnet-json-web-services/[^]
http://encosia.com/using-jquery-to-directly-call-aspnet-ajax-page-methods/[^]
 
I went through all of those before posting
 
Here's my scenario,
I have a GirdView in an UpdatePanel on one page, and I need to update it from another page.
Sounds simple, but obviously, when I use a static webmethod, I cannot refer to the gridview on the UpdatePanel,
 
Here's some code:
Page1.aspx
<script src="Scripts/jquery-1.4.1.js" type="text/javascript"></script>
    <script>
        function update() {
            jQuery.ajax({
                url: 'Page2.aspx/GetData',
                type: "POST",
                data: "{'userid':" + userid + "}",
                contentType: "application/json; charset=utf-8",
                dataType: "json",
                success: function (data) {
                    alert(data.d);
                    
                }
            });
        }
    </script>
</head>
<body>
    <form id="form1"  runat="server">
        <div>
    <input type="button" value="click me"  önclick="update();" />
    </div>
    <div>
    </form>
</body>
 
Page2.aspx: - This has the grid and the static method
<head  runat="server">
    <title></title>
    <script language="javascript">
        function update() {
            __doPostBack('UpdatePanel1', ''); //I can't call this!!
        }
    </script>
</head>
<body>
    <form id="form1"  runat="server">
    <asp:ScriptManager ID="ScriptManager1" runat="server" />
    <div>
    <asp:UpdateProgress ID="UpdateProgress1" AssociatedUpdatePanelID=UpdatePanel1 runat="server">
    <ProgressTemplate>
    WAIT!!!!
    </ProgressTemplate>
    </asp:UpdateProgress>
    <asp:UpdatePanel runat="server" ID="UpdatePanel1" onload="UpdatePanel1_Load">
    <ContentTemplate>
    <asp:GridView id=gv runat="server" AutoGenerateColumns=true>
    </asp:GridView>
    </ContentTemplate>
    </asp:UpdatePanel>
    </div>
    </form>
</body>
</html>
 
page2.aspx.cs
[WebMethod()]
       public static string GetData(int userid)
       {
           //UPDATE the GridView HERE!
       }
       protected void UpdatePanel1_Load(object sender, EventArgs e)
       {
           makeatableandbind();
       }
 
 
I cant call the UpdatePanel1_Load or cannot refer to the GridView from the static method
 
Im sure you guys here have done something like this
 
Need some help
Posted 8-Nov-12 19:10pm
saud_a_k1.2K
Comments
biswarup88 at 9-Nov-12 4:37am
   
Good Ques 5 from me.
waiting for positive answer.

1 solution

Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

The solution is to use __doPostBack, pretty simple
I didn't have time to share the solution....
here goes
Page 1
has gridview in an updatepanel
page 2
has some action, after which it should update the gridview on page 1
 
Page1 has some javascript like
function refresh()
{
 var btnid = '<%=btnUpdate.UniqueID%>'
 __doPostBack(btnid, "OnClick");
}
the the update panel with a gridview and a button
<asp:updatepanel id="UpdatePanel1" runat="server" onload="UpdatePanel1_Load" xmlns:asp="#unknown">
    <contenttemplate>
        <asp:gridview....>
    </asp:gridview....></contenttemplate>
    <triggers>
        <asp:asyncpostbacktrigger controlid="btnUpdate" eventname="Click" />
    </triggers>
</asp:updatepanel>
<asp:button id="btnUpdate" runat="server" style="display:none;" xmlns:asp="#unknown" />
 
and on page 2
    <script language="Javascript">
        function RefreshParent() {
            parent.refresh();
        }
    </script>

call this JavaScript function like:
ClientScript.RegisterClientScriptBlock(this.GetType(), "afterSave", "refresh();", true);
 

Hope this helps
  Permalink  
v3

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
0 OriginalGriff 375
1 RyanDev 135
2 CHill60 120
3 Richard MacCutchan 115
4 Sergey Alexandrovich Kryukov 110


Advertise | Privacy | Mobile
Web02 | 2.8.140709.1 | Last Updated 22 Jan 2013
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid