tags:

views:

289

answers:

2

Hi All;

Aspx Page:

$(document).ready(function() {

            $("#btnn").click(function() {
                $.ajax({
                    type: "POST",
                    url: "TestPage.aspx/emp",
                    data: "{}",
                    contentType: "application/json; charset=utf-8",
                    dataType: "json",
                    success: function(msg) {
                    }
                });
            });
        });

CodeBehind:

public void grdload()
    {
        GridView1.DataSource = GetEmployee("Select * from Employee");
        GridView1.DataBind();
    }

[WebMethod]
    public static void emp()
    {
        TestPage re = new TestPage();
        re.grdload();
    }

I Can't Gridview Data Load ? How To Make GridView Data Load?

Thank You

A: 

You cannot interact with the page in a WebMethod.

You should use an UpdatePanel instead.

SLaks
Man...you're stealing all my thunder this morning. :-P
Justin Niessner
+1  A: 

Calling WebMethods like that in ASP.NET is meant to return a JSON dataset that you can parse through Javascript, not reload controls.

You should look in to using the ASP.NET AJAX toolkit and getting the ScriptManager and UpdatePanel on your page and using regular .NET code to update your GridView.

Justin Niessner
I Don't Want Scriptmanager, Json Data With How To Make GridView Data Load ? Please Help...
Oraclee
You can't load a server-side control with client-side scripting (using JSON) without either ScriptManager/UpdatePanel or a post-back. It's that simple. Your other option would be to have your WebMethod return the HTML of the GridView and then use jQuery to dump the HTML on to the page.
Justin Niessner
@Justin Niessner, how its make "WebMethod return the HTML of the GridView and then use jQuery to dump the HTML on to the page"; im sorry, im junior developer :)
Oraclee
@oraclee Check out http://blogs.x2line.com/al/articles/859.aspx
Justin Niessner
@Justin Niessner, Thank You...
Oraclee