Wednesday, March 28, 2012

Calling a server side method from javascript without page methods

Hi everyone.

I'm trying to do some like this:

if (confirm("foo") == true) {

MyServerSideFunction();

}

Of course, I can call this function using PageMethods, but since this function in my code behind shold be static, I cannot call others methods inside my class.

Is there any way to call serer side methods without using PageMethods?

Thanks, and sorry for my bad english!

You can use ajax to call a webservice from javascript. Check out this article on how to do it:http://www.semenoff.dk/en/Code-Corner/ASP.Net.AJAX/WebService-From-JavaScript.aspx

Hope it helps


__doPostBack("ServerEventNameHere","");


Hi Everyone :)

@.Klaus Byskov Pedersen

I alread tryed using web services and it works fine, but it's not the case.

@.rpack79

Nice! It works! I noticed that I had to catch this requent inside my OnPageLoad and call the appropriated methods. Now one more question: And if I want do catch this postback inside an WebControl? Actualy I'm catching the postback event inside my control's OnInit event. Is it the right way?

Thanks a lot by the answers.

No comments:

Post a Comment