Monday, March 26, 2012

Call Server Side method from JavaScript function in Master Page

I have a JavaScript function in a Master Page. The function is below.

function Add(q, p) {//call server side method }

I want to be able from within the JavaScript Add function defined above, call a C# server side method and pass the values q and p to it. No value is returned.

I have tried PageMethods.CallServerSideMethod(q, p); but it will only work in a Page, not a master page.

Is there any way I can do this in a master page?

How about using a web service call?

Thanks for your help.

How could i code that? An example maybe?


The documentation has pretty good code examples. See if this helps: http://www.asp.net/AJAX/Documentation/Live/tutorials/ExposingWebServicesToAJAXTutorial.aspx

Niall20:

it will only work in a Page, not a master page.

That's because .master file can't work as a httpHandler to server the request. It's blocked. In a simple word, the method in master page can't be accessed from client side directly.

No comments:

Post a Comment