Is it possible to call asp.net codebehind function from javascript in vs2008?
My problem is, I have two codebehind methods, one is for some validation and it will return tru
To call a server side method on a client side event you need to do the following:
1- Create the server side method:
void DoSomething(...) { ... }
2- Implement the System.Web.UI.IPostBackEventHandler.RaisePostBackEvent
which take one string argument (You can assign the name to the value of this argument).:
public void RaisePostBackEvent(string eventArgument)
{
DoSomething(...);
}
3- Write a script to trigger post back:
function TriggerPostBack(control, arg){
__doPostBack(control, arg);
}
4- Call the PostBack trigger function when needed:
<a .... onclick="TriggerPostBack('control', 'arg')" .. />
In your case, why don't you use OnClientClick function of the button to call your javascript function?
Regards, S Mukherjee.
Yes by making use of PageMethods you can call the codebehind methods from javascript.
Check this link for more detail about pagemethods : http://aspalliance.com/1922_PageMethods_In_ASPNET_AJAX