The C# method is on the server. Javascript runs on the client (the user's browser). For the Javascript to interact with the web method, you need to use AJAX to run a request. Even then, the C# method needs to have a return type other than void, so it
returns some values for the javascript to work with. Although these examples call a server-side method that interacts with a database using jQuery, the basics are the same as you are trying to achieve:
http://www.mikesdotnetting.com/Article/104/Many-ways-to-communicate-with-your-database-using-jQuery-AJAX-and-ASP.NET
fewl
0 Points
2 Posts
calling c# method from JvaScript
Sep 16, 2009 05:06 PM|LINK
Good day.
In *.aspx.cs
Whats wrong? Why function call "select.strechGMap(h, w);" doesnt work?
Mikesdotnett...
All-Star
154818 Points
19853 Posts
Moderator
MVP
Re: calling c# method from JvaScript
Sep 16, 2009 07:21 PM|LINK
The C# method is on the server. Javascript runs on the client (the user's browser). For the Javascript to interact with the web method, you need to use AJAX to run a request. Even then, the C# method needs to have a return type other than void, so it returns some values for the javascript to work with. Although these examples call a server-side method that interacts with a database using jQuery, the basics are the same as you are trying to achieve: http://www.mikesdotnetting.com/Article/104/Many-ways-to-communicate-with-your-database-using-jQuery-AJAX-and-ASP.NET
Beginning ASP.NET Web Pages with WebMatrix | My Site | Twitter
watana72
Participant
1394 Points
267 Posts
Re: calling c# method from JvaScript
Sep 16, 2009 07:22 PM|LINK
1. use PageMethods instead of select.
The js call should be
Nitin.