Skip to content

Instantly share code, notes, and snippets.

@appforest
Created January 5, 2014 02:44
Show Gist options
  • Save appforest/8263634 to your computer and use it in GitHub Desktop.
Save appforest/8263634 to your computer and use it in GitHub Desktop.
PageMethods & Webmethods (JS & C#)
// Thanks to Enrico Ariel @ http://www.youtube.com/watch?v=Kp4jxrs6uuI
//The codebehind:
[WebMethod]
public static string GetValues(string value)
{
value = value +" - Sent @ " + DateTime.UtcNow.ToLongTimeString();
return value;
}
//The JS:
function getValues() {
var text1 = $("#TextBox1").val();
PageMethods.GetValues(text1, getValues_success, getValues_err);
}
function getValues_success(response) {
alert(response);
}
function getValues_err(errorMsg) {
alert(errorMsg.get_message());
}
//The ASP must include a ScriptManager like:
<asp:ScriptManager runat="server" ID="scriptManager1" EnablePageMethods="true"></asp:ScriptManager>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment