Introduction
This article helps us when we define a method in the code behind and want to call that method from the client side. JQuery has made life simple. There is a very easy way to do that.
Background
Earlier we knew one way that we needed to add our method as a webmethod, if we
want to call a method from the code behind at the client side. Using this, we can do it
without calling our method in webmethod. We cannot call server-side code
'directly' from client-side code. The reason is by design, the server side code
executes at server side and the client side code at the client. However there are
some workarounds.
Using the Code
In this example, I am writing a method to delete a particular user when a delete
key is hit. I don't want a postback so I want the event to execute client side.
I am writing a delete method server side in the CS file and calling it from
client side using JQuery.
Create a page with name Text.aspx. Now open its CS file, that is Test.aspx.cs
file and add a private method to delete a record. In this method, ID and UserId
parameters are coming from client side. So you can learn how to get the
parameters from client side.
This is my method in the CS file with the name DeleteRec.
private
void
DeleteRec()
{
int
ID= Request.Form["ID"].ToString().ToInteger();
//parameter send
//from clide side
int
UserID = Request.Form["UserID
"].ToString().ToInteger();//parameter
//send from clide side
UserBO lObjUserBO =
new
UserBO ();
lObjUserBO .DeleteUser(ID, UserID );
}
Join the conversation! Your thoughts help the community grow.
Sign in to leave a comment
It is the same account you read, post and publish with — and you will come straight back to this page.

Naveen VemanaPosted Dec 8, 2011, 12:10 AM
Plz keep a sample dowload app