Sigma Php Ajax framework, Ajax Components, GUI Builder
February 11, 2012, 08:06:43 AM *
Welcome, Guest. Please login or register.
Did you miss your activation email?

Login with username, password and session length
News:
 
   Home   Help Search Login Register  
Pages: [1]
  Print  
Author Topic: Call a server Function from javascript  (Read 3102 times)
gbolanoscruz
Moderator
Full Member
*****
Posts: 22


View Profile
« on: August 19, 2008, 01:36:36 PM »

Hi!

Many of you on any moment will need call a function on the server side, may be to get data from the database, or do something that you can't do on the client side. I'll try to explain how you can do that on ASP .net using Visual Basic .net

First, you'll need a reference to AJAX on you project. All that you need for that, you can find in this site:
http://www.asp.net/ajax/downloads/

When you finally made the reference to AJAX, we'll start to programing.

First, on your code, on the event Page_Load, you need add this line:



take note that you replace *class* for the name of the class that you are using.

example



Later do the function that you will need  call from javascript.. I will make a 'Hello World function' Smiley



now, when you make a function to call from javascript, you'll need add the reference to javascript on the function, so  the helloWorld function will be like that:



And Finish....  this is all that you need on the server side... go now to the client side, to the javascript code...

I'll make a javascript function to alert what return my VB function...



If you see, you need to send by parameter, the name of the function that will catch what return the VB function, we'll need to create that function:



who you can see, this function get response by parameter, on this variable is the data that the server send, if exist any problem, response.error will have the description of the error, but if response.error is empty, on response.value is the value responded by the server.

And that's it... this is all that you need to call a function on the server side from a javascript function on the client side... You need to know that exist a little delay between the request and the response, so, you need to think how to management that delay.


Any questions, post on this topic.

Ciao  Cheesy
Logged
steven
Moderator
Hero Member
*****
Posts: 546



View Profile
« Reply #1 on: August 20, 2008, 01:31:03 AM »

Hello gbolanoscruz,
Thank you for your sharing. It seems very interesting and I would like to get the data for feeding grid with data.
Logged

Sigma AJAX Data Grid - Easy to Integrate with PHP, ASP Classic, ASP.NET & Java
Sigma PHP Ajax Framework - WYSIWYG GUI Builder With Tree, Grid, Treegrid, Dialog, Tab & More Component
steven
Moderator
Hero Member
*****
Posts: 546



View Profile
« Reply #2 on: August 20, 2008, 01:33:53 AM »

It's really more elegant to retrieve the data
Logged

Sigma AJAX Data Grid - Easy to Integrate with PHP, ASP Classic, ASP.NET & Java
Sigma PHP Ajax Framework - WYSIWYG GUI Builder With Tree, Grid, Treegrid, Dialog, Tab & More Component
Pages: [1]
  Print  
 
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.7 | SMF © 2006-2008, Simple Machines LLC Valid XHTML 1.0! Valid CSS!