How to call java script function from code behind file in

Introduction: In previous articles i explained how to  show Message box in website using JavaScript and how to redirect visitor from one website to another website using java script  and How to show Validation guidelines in web forms using JavaScript in ? and Example to implement Jquery form validations and jQuery to Validate email address using RegularExpression and JavaScript validations in website 
 In this article i am going to explain how to call JavaScript function from code behind file.It is required many a times while working on application. Lets take an example:
  •  Declare a JavaScript function in the head tag of your design file as shown below:
<head runat="server">
    <title>Calling JavaScript From CodeBehind in file</title>
    <script type="text/javascript">
        function MyFunction() {
            alert('Demonstration Successfull..');

  • In order to call it from code behind, use the following code in your Page_Load
C#.Net Code to call java script function from code behind file in

protected void Page_Load(object sender, EventArgs e)
    if (!ClientScript.IsStartupScriptRegistered("alert"))
            "alert", "MyFunction();", true);

VB.Net Code to call java script function from code behind file in

If (Not ClientScript.IsStartupScriptRegistered("alert")) Then
    Page.ClientScript.RegisterStartupScript _
    (Me.GetType(), "alert", "MyFunction();", True)
End If

Now over to you:
"If you like my work; you can appreciate by leaving your comments, hitting Facebook like button, following on Google+, Twitter, Linked in and Pinterest, stumbling my posts on stumble upon and subscribing for receiving free updates directly to your inbox . Stay tuned and stay connected for more technical updates."
Next Post »


Click here for comments
March 16, 2013 ×

very useful....keep the nice writing

September 06, 2013 ×


August 28, 2014 ×

Thanks is always nice to hear that my articles helped anyone..stay connected and keep reading for more useful updates like this..:)


If you have any question about any post, Feel free to ask.You can simply drop a comment below post or contact via Contact Us form. Your feedback and suggestions will be highly appreciated. Also try to leave comments from your account not from the anonymous account so that i can respond to you easily..