Search

Monday, January 27, 2014
0 comments

Run JavaScript code in Page_Load method, ASP.NET RegisterClientScriptBlock

8:49 AMMonday, January 27, 2014
The RegisterClientScriptBlock method allows you to run JavaScript function at the top of the browser page. It means Script run on Page_Load method. Lets take an simple example of that in ASP.NET.
<%@ Page Language="C#" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<script runat="server">

    protected void Page_Load(object sender, EventArgs e)
    {
        string script = @" function Hello(){alert ('Welcome to dotprogramming.blogspot.com');}";
        Page.ClientScript.RegisterClientScriptBlock(this.GetType(), "MY Code", script, true);
        
    }
</script>

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
</head>
<body onload ="Hello()">
    <form id="form1" runat="server">
    
    </form>
</body>
</html>

Code Generate the following output

Run JavaScript code in Page_Load method, ASP.NET RegisterClientScriptBlock

Protected by Copyscape Online Copyright Protection Software

0 comments :

Post a Comment

 
Toggle Footer
Top