Wrox Programmer Forums
Go Back   Wrox Programmer Forums > ASP.NET and ASP > ASP.NET 2.0 > Visual Web Developer 2005
|
Visual Web Developer 2005 Discuss creating ASP.NET 2.0 sites with Microsoft's Visual Web Developer 2005. If your question is more specific to a piece of code than the Visual tool, see the ASP.NEt 2.0 forums instead.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Visual Web Developer 2005 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 January 22nd, 2011, 03:00 AM
Authorized User
Points: 410, Level: 7
Points: 410, Level: 7 Points: 410, Level: 7 Points: 410, Level: 7
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Oct 2009
Posts: 72
Thanks: 17
Thanked 0 Times in 0 Posts
Unhappy Call a Server side function from Javascript

Hi,

I want to call a Server side function in a JavaScript function.

I tried the following but it didn't worked.

function A()
{
var Result;
Result = confirm('Are you sure want to continue?');
if(Result==true)
{
<% MyMethod()%>;
}
}
 
Old January 22nd, 2011, 04:04 AM
Imar's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
Default

Hi there,

You can use AJAX call backs for this.

For a concrete implementation, take a look here: http://imar.spaanjaars.com/494/check...th-aspnet-ajax

For more general info: http://www.google.com/#sclient=psy&h...d5fec803d17261

Cheers,

Imar
__________________
Imar Spaanjaars
http://Imar.Spaanjaars.Com
Follow me on Twitter

Author of Beginning ASP.NET 4.5 : in C# and VB, Beginning ASP.NET Web Pages with WebMatrix
and Beginning ASP.NET 4 : in C# and VB.
Did this post help you? Click the button below this post to show your appreciation!
 
Old January 22nd, 2011, 03:45 PM
Friend of Wrox
 
Join Date: Jun 2007
Posts: 477
Thanks: 10
Thanked 19 Times in 18 Posts
Default

Quote:
Originally Posted by anup.maverick View Post
function A()
{
var Result;
Result = confirm('Are you sure want to continue?');
if(Result==true)
{
<% MyMethod()%>;
}
}
This ironically makes sense. <% MyMethod()%> is server side code and has to be processed by the server. JS is only executed after the server has finished what it's doing, downloaded the resulting page to the user's web browser. That's when the JS runs. So by the time the the JS evaluates your if statement the MyMethod() call is sitting in IE or Firefox and it has no idea what to do with the server side code.

Depending on what you're trying to do you may be able to do something as simple as a postback. If that seems too big a response for what you want to do, than AJAX and the resources Imar listed can let you use a lighter touch.
__________________
-------------------------

Whatever you can do or dream you can, begin it. Boldness has genius, power and magic in it. Begin it now.
-Johann von Goethe

When Two Hearts Race... Both Win.
-Dove Chocolate Wrapper

Chroniclemaster1, Founder of www.EarthChronicle.com
A Growing History of our Planet, by our Planet, for our Planet.





Similar Threads
Thread Thread Starter Forum Replies Last Post
call javascript function from codebehind to show modelpopup swathi reddy ASP.NET 2.0 Basics 0 April 30th, 2010 12:56 AM
call serverside event from client side function CodeBest ASP.NET 2.0 Basics 0 January 12th, 2009 08:00 AM
How to call javascript function from VB function vinod_yadav1919 VB How-To 0 February 13th, 2006 06:03 AM
Help with Javascript function call fakeeyed Javascript 1 January 15th, 2006 04:27 AM
Can dropdownlist OnFocus call a server-side method commerceJeff ASP.NET 1.0 and 1.1 Basics 6 July 19th, 2004 11:50 AM





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