Wrox Programmer Forums
Go Back   Wrox Programmer Forums > ASP.NET and ASP > ASP.NET 1.0 and 1.1 > ASP.NET 1.0 and 1.1 Professional
|
ASP.NET 1.0 and 1.1 Professional For advanced ASP.NET 1.x coders. Beginning-level questions will be redirected to other forums. NOT for "classic" ASP 3 or the newer ASP.NET 2.0 and 3.5
Welcome to the p2p.wrox.com Forums.

You are currently viewing the ASP.NET 1.0 and 1.1 Professional 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 November 18th, 2009, 09:31 AM
Authorized User
 
Join Date: Feb 2008
Posts: 37
Thanks: 0
Thanked 0 Times in 0 Posts
Post Does anyone know if it is possible to call a C# method from a javascript in ASPX page

Does anyone know if it is possible to call a C# method from a javascript in theASPX page?

e.g:- I have ASPX page (Page1) and a different C# file (File1, which is not the code-behind file of Page1).
 
Old November 18th, 2009, 09:48 AM
Wrox Author
 
Join Date: Oct 2005
Posts: 4,104
Thanks: 1
Thanked 64 Times in 64 Posts
Send a message via AIM to dparsons
Default

No you can't do that. Depending on what the Method does in the C# class you could setup an AJAX style request, however, this would require you to create a webpage that linked up to the C# file.

What are you trying to do?
__________________
===============================================
Doug Parsons
Wrox online library: Wrox Books 24 x 7
Did someone here help you? Click on their post!
"Easy is the path to wisdom for those not blinded by themselves."
===============================================
 
Old November 18th, 2009, 09:54 AM
Authorized User
 
Join Date: Feb 2008
Posts: 37
Thanks: 0
Thanked 0 Times in 0 Posts
Post Does anyone know if it is possible to call a C# method from a javascript in ASPX page

From the javascript in the aspx page 1, the control goes to different C# file1 by the javascript call.

In C# file1, i have a validation(which inturn calls Oracle stored proc) to check if it is success or failure. Right now success and failure message are hardcoded and shown in the Web page based on whether exception is thrown or not.

But going forward , they would have some message coming back from the stored proc which i need to show in the Web page.

Thats what i am trying to see if that is possible.
 
Old November 18th, 2009, 10:03 AM
Wrox Author
 
Join Date: Oct 2005
Posts: 4,104
Thanks: 1
Thanked 64 Times in 64 Posts
Send a message via AIM to dparsons
Default

Ya you can not directly access a C# class file via JavaScript, however, Microsoft does provide you with some funcationality that makes this somewhat possible. Since you are using .NET 1.x you do not have the luxary of using [WebMethod] to expose Server Side events to your JavaScript but you can setup a Script Callback. This essentially allows you to call a server side method directly from your JavaScript.

Understand though you can't call the C# file directly. The Script Callback must call a Method that exists in your ASPX page and that method can then call your C# file.

Here is how to setup a Script Callback: http://www.codeguru.com/csharp/.net/...icle.php/c9679

hth.
-Doug
__________________
===============================================
Doug Parsons
Wrox online library: Wrox Books 24 x 7
Did someone here help you? Click on their post!
"Easy is the path to wisdom for those not blinded by themselves."
===============================================
 
Old November 18th, 2009, 10:09 AM
Authorized User
 
Join Date: Feb 2008
Posts: 37
Thanks: 0
Thanked 0 Times in 0 Posts
Default Does anyone know if it is possible to call a C# method from a javascript in ASPX page

Thanks. I will go through the article and see how it can be done.





Similar Threads
Thread Thread Starter Forum Replies Last Post
Javascript isnt work well on my aspx page msbsam ASP.NET 2.0 Professional 1 July 11th, 2008 08:00 AM
Javascript with aspx page zaheerabbas.sk ASP.NET 1.0 and 1.1 Professional 2 April 4th, 2007 11:36 PM
aspx page not loading!!!! Method called too soon dba123 C# 0 August 6th, 2006 11:18 PM
How to call a method on a remote object eloyitomio C# 1 July 21st, 2006 10:17 AM
Javascript Works Fine in Aspx page but... vivek_inos Javascript 0 June 14th, 2006 01:57 AM





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