tags:

views:

103

answers:

1

Hi All;

How do I run a webmethod with jQuery. Asp.Net the method load it the GridView

[WebMethod]
        public void GetGrid()
        {
            DataProviderDataContext db = new DataProviderDataContext();
            GridView1.DataSource = db.Employees.ToList();
            GridView1.DataBind();
        }
<asp:GridView ID="GridView1" runat="server">
        </asp:GridView>
A: 

In short, you can't do this, not the way you want. Server controls execute on the server, their rendered HTML is what's set to the client, you can't just update a client section of the page from a server-control, there are extra steps (an UpdatePanel, for a quick-fix approach for example).

I think there are some basic confusion areas here around client/server and how ASP.Net works with with server controls. I recommend that you look at how-to's using ASP.Net with jQuery AJAX, encosia has some excellent articles for just this:

Nick Craver