Sponsored Ad

Wednesday, July 7, 2010

How to use RegisterClientScriptBlock method to run javascript code in C#

This is an exaple of RegisterClientScriptBlock to run write the javascript code in C# and run it.

The exaple example is given in this code, you can write your own complex code by taking help of this small program.

 

How to use RegisterClientScriptBlock method to run javascript code in C#

How to use RegisterClientScriptBlock method to run javascript code in C#

<%@ Page Language="C#" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" >

<script runat="server">
    protected void Page_Load(object sender, EventArgs e)
    {
        string myScript = @" function RunCode() { alert(' This is example of RegisterClientScriptBlock'); }";
        Page.ClientScript.RegisterClientScriptBlock(this.GetType(), "MyScript", myScript, true);
    }
</script>

<html xmlns="”>
<head>
    <title>How to use RegisterClientScriptBlock method to run javascript code.</title>
</head>
<body>
    <form id="form1" runat="server">
        <div>
            <asp:Button ID="btnClick" Text="Click" runat="server" OnClientClick="RunCode(); return false;" />
        </div>
    </form>
</body>
</html>

1 comments:

Sponsored Ad

More Related Articles

Website Update

Followers