Hi,
The ClientScriptManager.RegisterStartupScript
method allows you to inject at client JS when the page postback. Is that what you would like to achieve?
Here is a sample process of how it is being used in the form designer. You can open the Form / .NET tabs to view the code behind I have added.
https://advantys.box.com/s/m5t46uv0sfh27bjobxduwshms6f7ipdh
Form / .NET / Code Behind
// Place here your ASP.NET procedures and global variables.
// It will be declared within a <script runat="server"> block,
// and placed before the opening <html>.
// Do not include the <script runat="server"> tag.
// Use the Control key + Spacebar to show the keywords list.
// ***********************************************************
protected void Page_Load(object sender, EventArgs e)
{
base.Page_Load(sender, e);
// Define the name and type of the client scripts on the page.
String csname1 = "PopupScript1";
Type cstype = this.GetType();
// Get a ClientScriptManager reference from the Page class.
ClientScriptManager cs = Page.ClientScript;
// Check to see if the startup script is already registered.
if (!cs.IsStartupScriptRegistered(cstype, csname1))
{
StringBuilder cstext1 = new StringBuilder();
cstext1.Append("<script type=text/javascript> alert('JS injected at Page_Load') </");
cstext1.Append("script>");
cs.RegisterStartupScript(cstype, csname1, cstext1.ToString());
}
}
protected void REQUEST_BUTTON1_Click(object sender, EventArgs e)
{
// Define the name and type of the client scripts on the page.
String csname1 = "PopupScript2";
Type cstype = this.GetType();
// Get a ClientScriptManager reference from the Page class.
ClientScriptManager cs = Page.ClientScript;
// Check to see if the startup script is already registered.
if (!cs.IsStartupScriptRegistered(cstype, csname1))
{
StringBuilder cstext1 = new StringBuilder();
cstext1.Append("<script type=text/javascript> alert('JS injected on custom button click event') </");
cstext1.Append("script>");
cs.RegisterStartupScript(cstype, csname1, cstext1.ToString());
}
}