DotNet Academy of Rajesh Rolen

Solutions by Rajesh Rolen

Execute JavaScript function from ASP.NET codebehind

by declaring a JavaScript function in your code as shown below you can easly do it:

JavaScript


< head runat="server" >

< title >Call JavaScript From CodeBehind< /title >

< script type="text/javascript" >



function alertMe() {

alert('Hello');

}

< /script >

< /head >



now write below code in Page_Load to call it from code behind:

VB.NET


If (Not ClientScript.IsStartupScriptRegistered("alert")) Then

Page.ClientScript.RegisterStartupScript _

(Me.GetType(), "alert", "alertMe();", True)

End If

C#


if (!ClientScript.IsStartupScriptRegistered("alert"))

{

Page.ClientScript.RegisterStartupScript

(this.GetType(), "alert", "alertMe();", true);

}








The Page.ClientScript.RegisterStartupScript() allows you to emit client-side script blocks from code behind.

0 comments:

Post a Comment

About this blog

My Blog List

Advertise On This Site

Site Info

Advertise on this Site

To advertise on this site please mail on RajeshRolen@gmail.com

Information Source

About

Pages

Dot Net Academy

Advertis in This Area of Site

Powered by Blogger.

Followers

Search This Blog