Trying to transfer JavaScript code built using String Builder on the server-side (ASP.NET) to the HTML page's JavaScript. Here is my approach:
Utilizing a Master Page and an ASPX page structured like this:
<asp:Content ID="BodyContent" ContentPlaceHolderID="MainContent" runat="server">
<script type="text/javascript>
// Initial JavaScript code
// Then a Literal tag, intended to be replaced by
// JavaScript code from the server-side
<asp:Literal runat="server" ID="SomeID"></asp:Literal>
// Additional JavaScript.
</script>
</asp:Content>
In the code-behind ASPX.CS file:
protected void Page_Load(object sender, EventArgs e)
{
Literal ID = (Literal)this.Page.FindControl("SomeID");
ID.Text = SomeStuff();
}
private string SomeStuff()
{
string javascript = "";
StringBuilder sb = new StringBuilder();
sb.Append("JavaScript Code");
sb.Append("generated dynamically on the server-side");
}
Encountering an issue where this.Page.FindContol("SomeID") returns NULL. The Literal ID seems inaccessible when within script tags. Unable to wrap div or span tags around the Literal control inside the script tags as it would create extra markup in the JavaScript code. Any assistance is welcomed.
Thank you!