Facebook Twitter Gplus LinkedIn YouTube Google Maps RSS
Home Technical Call Server Side methods from JavaScript
formats

Call Server Side methods from JavaScript

Some times we need to call server side function from Javascript function.For example,callig a PoupWindow(with value from code behind) on HyperLink click.

This must be implemented by creating a additional request to the web server and that’s the only way to invoke methods on the server. Page methods are used for this.

What is PageMethod?

A PageMethod is a public static method that is exposed in the code-behind of a page and can be called from the client script. PageMethods are annotated with [System.Web.Services.WebMethod] attribute.

The code is simple..

Server side function

[code:c#]
[System.Web.Services.WebMethod] public static void Score(string ID, string name, string Role) {
try {
//Some data manipulations
return finalScore ;
}
catch (Exception ex) {
//Response.Write(ex.ToString());
}
}
[/code]

//Client Side function

[code:c#]
function score()
{
PageMethods.Score(txtID.value,txtName.value,txtRole.value);
}
[/code]

<asp:HyperLink ID=”btn_Test” runat=”server” Text=”Calculate” OnClientClick=”javascript:return score();”/>

– From VijayKodali.com

 
 Share on Facebook Share on Twitter Share on Reddit Share on LinkedIn
No Comments  comments 

Leave a Reply

Your email address will not be published. Required fields are marked *

*

* Copy this password:

* Type or paste password here:

12,871 Spam Comments Blocked so far by Spam Free Wordpress

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

© All rights reserved to Cyberbrutus. 2012
credit

Switch to our mobile site