Call server side events and functions from Javascript

naimish's Avatar author of Call server side events and functions from Javascript
This is an article on Call server side events and functions from Javascript in ASP.
Rated 5.00 By 1 users

Introduction



To call server side events and functions from client side javascript function in asp.net.

Suppose we want to perform both client side and server side activities for an event,we can use this logic

Background



Three are 2 ways to acheive this functionality.

one using __dopostback() and another using form.submit(). Say you are having a client side javascript function named clientfunction. From clientfunction if u want to call any serverside function or serverside event(eg: dropdown selected index change) say server function and serverdropdown.

The code




Code:
function clientfunction
{
	//do the client side validations here
	//
	//now call the server side dropdown event explicitly
	__doPostBack('cboserverdropdown','');
}
Code:
function clientfunction
{
	//do the client side validations here
	//
	//or just give below code
	form.submit();
}
pradeep's Avatar, Join Date: Apr 2005
Team Leader
This works only for ASP.net, if there any way to this in other languages like PHP?
shabbir's Avatar, Join Date: Jul 2004
Go4Expert Founder
Nomination for Article of the month - Sep 2009 Started. Nominate this article.
djbrown's Avatar, Join Date: Oct 2009
Go4Expert Member
This works only for ASP.net?
technica's Avatar, Join Date: Dec 2007
CoderByNature
I am looking for the way to do this in classic asp 3.0 language. If you know how to do it then please post article for that too. By the way this article is good.