Click here to Skip to main content
12,892,796 members (48,659 online)
Rate this:
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:[^][^][^]

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:
<script src="Scripts/jquery-1.4.1.js" type="text/javascript"></script>
        function update() {
                url: 'Page2.aspx/GetData',
                type: "POST",
                data: "{'userid':" + userid + "}",
                contentType: "application/json; charset=utf-8",
                dataType: "json",
                success: function (data) {
    <form id="form1"  runat="server">
    <input type="button" value="click me"  önclick="update();" />

Page2.aspx: - This has the grid and the static method
<head  runat="server">
    <script language="javascript">
        function update() {
            __doPostBack('UpdatePanel1', ''); //I can't call this!!
    <form id="form1"  runat="server">
    <asp:ScriptManager ID="ScriptManager1" runat="server" />
    <asp:UpdateProgress ID="UpdateProgress1" AssociatedUpdatePanelID=UpdatePanel1 runat="server">
    <asp:UpdatePanel runat="server" ID="UpdatePanel1" onload="UpdatePanel1_Load">
    <asp:GridView id=gv runat="server" AutoGenerateColumns=true>

       public static string GetData(int userid)
           //UPDATE the GridView HERE!
       protected void UpdatePanel1_Load(object sender, EventArgs e)

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
biswarup88 9-Nov-12 4:37am
Good Ques 5 from me.
waiting for positive answer.

1 solution

Rate this: bad
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">
        <asp:asyncpostbacktrigger controlid="btnUpdate" eventname="Click" />
<asp:button id="btnUpdate" runat="server" style="display:none;" xmlns:asp="#unknown" />

and on page 2
<script language="Javascript">
    function RefreshParent() {

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

Hope this helps

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

    Print Answers RSS
Top Experts
Last 24hrsThis month

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

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100