This isn't a duplicate, I have already read and tried all suggestions from the following:
- RegisterStartupScript doesn't work with ScriptManager,Updatepanel. Why is that?
- https://msdn.microsoft.com/en-us/library/asz8zsxy(v=vs.110).aspx
- ScriptManager.RegisterStartupScript code not working - why?
- Page.ClientScript.RegisterStartupScript doesn't work - why?
- RegisterStartupScript doesn't appear to be working on page postback within update panel
- https://codewala.net/2011/11/24/page-clientscript-registerstartupscript-is-not-working/
I have tried numerous permutations and experiments from the above mentioned forum topics and articles, and in no case does my javascript get registered and executed. I have tried viewing source - my script doesn't appear. As a sanity check I injected my javascript into an ASP.NET Literal control, and that works fine, and my js executes.
Here is my ASP.NET page, pretty simple:
<%@ Page language="c#" Trace="false" EnableSessionState="true" EnableViewState="false" AutoEventWireup="false" Codebehind="PopOut.aspx.cs" Inherits="MySystem.MPC.WebComponents.Configurator.UI.PopOut" %>
<!DOCTYPE html>
<html>
<head>
<base target="_self" />
<title>MySystem Test</title>
<link type="text/css" rel="stylesheet" href="site/styles/Common/Core.css" />
<script type="text/javascript" src="scripts/JSUI.js"></script>
</head>
<body onload="loadWindow();" onunload="unloadWindow();">
<div class="xCfg" popout>
<div class="xTb" id="POPOUP_TOOLBAR">
<div class="xTbBtns">
<a id="b12" onclick="return expTbClick(event, 12);" href="">
<img src=""><span></span>
</a>
<a id="b14" onclick="return expTbClick(event, 14);" href="">
<img src="">
</a>
</div>
</div>
<div class="xBody" id="POPOUT_BODY" scrollable>
<div class="xPage" id="bodyContent" notitle>
<div class="xPopOutLargeText" id="loading"></div>
<div class="xPopOutLargeText" id="allHidden" style="display: none;"></div>
</div>
</div>
<div class="xSb" id="POPOUP_STATUSBAR"></div>
</div>
</body>
</html>
And my codebehind:
using System;
using System.Linq;
using System.Text;
using System.Web.UI;
using System.Web.UI.WebControls;
namespace MySystem.UI {
public class PopOut : ConfigPageBase {
protected Literal uiStyleLink;
protected Literal litScript;
protected override void OnLoad(EventArgs e) {
base.OnLoad(e);
uiStyleLink.Text = string.Format("<link href=\"/experlogix/site/styles/{0}/{0}.css?{1}\" rel=\"stylesheet\" type=\"text/css\">",
ExpSettings.Site.UserInterface.Theme,
GlobalState.StaticResourceVarianceParameter);
}
protected override void OnPreRender( EventArgs e ) {
//base.OnPreRender(e);
this.ClientScript.RegisterClientScriptBlock(this.GetType(), "key1", "<script>alert('testing');</script>");
[and various other approaches as per posts and articles above]
}
}
}
Also, I tried adding a <form runat="server">
(plus closing at end) but it made no difference.
Any ideas?
RegisterStartupScript
in your question. Your question needs to demonstrate your issue. – mason