Calling Javascript From Any Part Of Code Behind Page By Registering The Script

Description:

Calling javascript function in codebehind just by registering the script
Here I am using textbox to show how to register the script in the code behind.
In the OnTextChanged event I am showing the PopUp Message Box.

TextBox.aspx:



<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" Runat="Server">

<asp:TextBox ID="txt" runat="server" OnTextChanged="txt_OnTextChanged" AutoPostBack="true">asp:TextBox>
asp:Content>


TextBox.aspx.cs:

protected void txt_OnTextChanged(object sender, EventArgs e)

{
ScriptManager.RegisterStartupScript(this, GetType(), "alert", "alert('this is test alert')", true);
}

0 Responses to “Calling Javascript From Any Part Of Code Behind Page By Registering The Script”

Post a Comment

Labels

Topics