How to call c# method from js function [Resolved]

Posted by Priyankapandit under ASP.NET AJAX on 11/21/2017 | Points: 10 | Views : 213 | Status : [Member] | Replies : 2
In my application I need to call c# method from js function call.

I tried...

<img id='img2' width="9px" border="0" src="plus.gif" onclick="MyHeader()"/> Header <div>
<asp:GridView ID="grdHeader" runat="server" AutoGenerateColumns="false">
<Columns>
</Columns>
</asp:GridView></div>


My JS Function:

function MyHeader() {
PageMethods.BindHeaderGrid();
}


My c# method:

[WebMethod]
public void FillHeaderGrid()
{
grdHeader.DataSource = ds.Tables[0];
grdHeader.DataBind();
}


But it is not working.




Responses

Posted by: Priyankapandit on: 11/21/2017 [Member] Starter | Points: 25

Up
0
Down

Resolved
Ohhh wow, its working

Thanks for fast replay...

Priyankapandit, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Dharmraj on: 11/21/2017 [Member] Starter | Points: 25

Up
2
Down
Just you need to make method as static.

You can take reference to this...

https://forums.asp.net/t/1273944.aspx?How+to+use+PageMethod+to+call+Server+side+data+in+Javascript+code+

http://www.c-sharpcorner.com/UploadFile/8911c4/how-to-call-C-Sharp-methodfunction-using-jquery-ajax/


Dharmraj Thakur

Priyankapandit, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response