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.
<%@ 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: