p2p.wrox.com Forums

p2p.wrox.com Forums (http://p2p.wrox.com/index.php)
-   General .NET (http://p2p.wrox.com/forumdisplay.php?f=122)
-   -   Calling a .NET function from javascript (http://p2p.wrox.com/showthread.php?t=29744)

jainnid May 25th, 2005 09:52 AM

Calling a .NET function from javascript
Is it possible to call a .net function from javascript.
Nidhi Jain

planoie June 1st, 2005 08:39 AM

No. Javascript runs on the client not the server.

However, there are methods of making client callbacks within javascript using the HttpXml object or a framed page or similar method. The XML method is known as AJAX.



belesisj June 3rd, 2005 03:45 AM

If refreshing the page isnt an issue you could always pass querystring values using the javascript redirect to pass variables to a function. Thats what I usually do.

jainnid June 6th, 2005 03:05 AM

Hi belesisj
Could give a sample code for the same please.

Prashant.k.m June 6th, 2005 06:38 AM


There is a raw method to attain a similar task.
ASP.Net Uses the __dopostback(ctl,arg) script to handle the events your page. so you can put a linkbutton with no text. Call you function from the linkbutton_click event and call __dopostback('lnkbtn',''); in you javascript function.

Note: make sure that your asp.net we page has a at least one postback control so that asp.net will emit the __dopostback script.
Also this may not work in future versions of Asp.Net


planoie June 7th, 2005 01:09 PM

Instead of hardcoding the postback method name in your page script, I'd recommend you use the GetPostBackEventReference() method off the Page class. This will return you the generated method name and will most likely be forward compatible. It also handles the issue of ensuring that the client-side method is emitted to the page markup.


ASP.NET 2.0 has a feature call "client call-backs" which perform exactly what you are looking for. They can be activated within the 2.0 GridView control (similar to DataGrid) so that the body of the grid is redrawn without the need for a full page postback.


Prashant.k.m June 8th, 2005 04:54 AM

Thats a better one

Thanks Peter

All times are GMT -4. The time now is 03:40 PM.

Powered by vBulletin®
Copyright ©2000 - 2019, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.