Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > .NET > Other .NET > General .NET
Password Reminder
Register
Register | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
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 tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old May 25th, 2005, 09:52 AM
Authorized User
 
Join Date: Aug 2004
Location: , , .
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

Reply With Quote
  #2 (permalink)  
Old June 1st, 2005, 08:39 AM
planoie's Avatar
Friend of Wrox
Points: 16,481, Level: 55
Points: 16,481, Level: 55 Points: 16,481, Level: 55 Points: 16,481, Level: 55
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Aug 2003
Location: Clifton Park, New York, USA.
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
Reply With Quote
  #3 (permalink)  
Old June 3rd, 2005, 03:45 AM
Registered User
 
Join Date: Jun 2005
Location: Athens, , Greece.
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.
Reply With Quote
  #4 (permalink)  
Old June 6th, 2005, 03:05 AM
Authorized User
 
Join Date: Aug 2004
Location: , , .
Posts: 10
Thanks: 0
Thanked 0 Times in 0 Posts
Default

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



Reply With Quote
  #5 (permalink)  
Old June 6th, 2005, 06:38 AM
Friend of Wrox
 
Join Date: Apr 2005
Location: Cochin, , India.
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


Reply With Quote
  #6 (permalink)  
Old June 7th, 2005, 01:09 PM
planoie's Avatar
Friend of Wrox
Points: 16,481, Level: 55
Points: 16,481, Level: 55 Points: 16,481, Level: 55 Points: 16,481, Level: 55
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Aug 2003
Location: Clifton Park, New York, USA.
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
Reply With Quote
  #7 (permalink)  
Old June 8th, 2005, 04:54 AM
Friend of Wrox
 
Join Date: Apr 2005
Location: Cochin, , India.
Posts: 186
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Thats a better one

Thanks Peter

Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


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



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


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