Asp.net programming we consider all important topic for knowledge about controls,web Services, JSON, Ajax, database, and interview related Question. In this Asp.net and sql server tutorial blog we give many examples of jquery as like How Play YouTube Video in Your Asp.net Website by URL, How to Play YouTube Videos in Asp.net by using Jquery , Jquery Change div background on mouseover in asp.net , JQuery UI Datepicker (Calendar) etc.

Thursday, April 23, 2015

Execute JavaScript function from ASP.NET or codebehind C# code file

Execute  a Javascript function from c# code:




Calling a JavaScript function from codebehind is quiet simple, yet it confuses a lot of developers.

Here's how to do it. Declare a JavaScript function in your code as shown below:

JavaScript function on aspx page :

<head runat="server">

    <title>Call JavaScript From CodeBehind</title>

    <script type="text/javascript">

        function alertMe()
        {
            alert('Hello');
        }
    </script>

</head>

C# code for call javascript function on aspx.cs page :


protected void Page_Load(object sender, EventArgs e)

{

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

    {

        Page.ClientScript.RegisterStartupScript(this.GetType(),

            "alert", "alertMe();", true);

    }


}





Other Asp.net Related Post:


No comments:

Post a Comment