Auto Ad Code

Thursday, June 24, 2010

Calling a Server side function from Javascript

Many of us needs a server side function to be called from JavaScript. We can do this easily using __doPostBack
as

Javascript Code

function CallServerCode()
{
__doPostBack('btnTest', '');
}


and in HTML

<­button type="­button" onclick="javascript:CallServerCode();">Call Server Code<­/­button­>
<­asp­:­linkbutton id="btnTest" runat="server" text="ASP .Net Button"­> <­/­asp­:­linkbutton>

and the Server side code
Protected Sub btnHidden_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnTest.Click
Response.Write("Hello")
End Sub


Now note that whenever the client button with caption "Call Server Code" will be clicked it will call Serverside event of btnTest using Javascript.

No comments:

Post a Comment