Wrox Programmer Forums
Go Back   Wrox Programmer Forums > .NET > Other .NET > General .NET
|
General .NET For general discussion of MICROSOFT .NET topics that don't fall within any of the other .NET forum subcategories or .NET language forums.  If your question is specific to a language (C# or Visual Basic) or type of application (Windows Forms or ASP.Net) try an applicable forum category. ** PLEASE BE SPECIFIC WITH YOUR QUESTION ** When posting here, provide details regarding the Microsoft .NET language you are using and/or what type of application (Windows/Web Forms, etc) you are working in, if applicable to the question. This will help others answer the question without having to ask.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the General .NET section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old May 25th, 2005, 09:52 AM
Authorized User
 
Join Date: Aug 2004
Posts: 10
Thanks: 0
Thanked 0 Times in 0 Posts
Default Calling a .NET function from javascript

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

 
Old June 1st, 2005, 08:39 AM
planoie's Avatar
Friend of Wrox
 
Join Date: Aug 2003
Posts: 5,407
Thanks: 0
Thanked 16 Times in 16 Posts
Default

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.

http://en.wikipedia.org/wiki/AJAX

-Peter
 
Old June 3rd, 2005, 03:45 AM
Registered User
 
Join Date: Jun 2005
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Default

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.
 
Old June 6th, 2005, 03:05 AM
Authorized User
 
Join Date: Aug 2004
Posts: 10
Thanks: 0
Thanked 0 Times in 0 Posts
Default

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



 
Old June 6th, 2005, 06:38 AM
Friend of Wrox
 
Join Date: Apr 2005
Posts: 186
Thanks: 0
Thanked 0 Times in 0 Posts
Default

hi,

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

Prashant


 
Old June 7th, 2005, 01:09 PM
planoie's Avatar
Friend of Wrox
 
Join Date: Aug 2003
Posts: 5,407
Thanks: 0
Thanked 16 Times in 16 Posts
Default

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.

http://msdn.microsoft.com/library/en...rencetopic.asp

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.

-Peter
 
Old June 8th, 2005, 04:54 AM
Friend of Wrox
 
Join Date: Apr 2005
Posts: 186
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Thats a better one

Thanks Peter






Similar Threads
Thread Thread Starter Forum Replies Last Post
Calling VBScript Function from javascript arnabghosh Classic ASP Professional 1 July 13th, 2007 08:32 AM
Calling javascript function from with in ASP kawal.singh Classic ASP Basics 1 July 4th, 2007 05:17 AM
Calling a javascript function from C# SebFr C# 0 November 3rd, 2006 12:05 PM
Calling Javascript Function With Attributes.Add OutCaster ASP.NET 1.0 and 1.1 Basics 1 January 27th, 2006 09:53 PM
On calling javascript function only one value pops shoakat Classic ASP Components 4 April 24th, 2005 06:07 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.