Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 307577
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T07:34:16+00:00 2026-05-12T07:34:16+00:00

I know there’s an easy answer to this, but this comes in the form

  • 0

I know there’s an easy answer to this, but this comes in the form of 2 problems.

Problem 1:

In an asp.net page there is a javascript block like this:

<script type="text/javascript">
    function doSomethingRandom() {
        var myVarToUse = <asp:Literal runat="server" ID="HackyLiteral" />
    }
</script>

Ok, so it’s a simplified version of the problem, but it should be clear. I now want to move this function in to a JS file…but I can’t get the asp:Literal into the JS.

var myVarToUse = <asp:Literal runat="server" ID="HackyLiteral" />
<script src="myJSFile.js" />

…Makes me a little sick, is there a better way?

Problem 2:

Similar problem, but this time the second version looks like this:

<asp:ScriptManagerProxy runat="server">
    <Scripts>
        <asp:ScriptReference Path="~/tree/AttributeTree.js" />
    </Scripts>
</asp:ScriptManagerProxy>

But this time I can’t realistically put the

var myVarToUse = <asp:Literal runat="server" ID="HackyLiteral" />

above it because with the ScriptManagerProxy there’s no real way of knowing exactly where the script file is going to appear.

So, them’s the problems! Thanks.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-12T07:34:17+00:00Added an answer on May 12, 2026 at 7:34 am

    We use the Page‘s RegisterStartupScript method to register initialization functions with the ClientScriptManager. Our Javascript files only contain functions and are loaded via ScriptManager (like in your snippet). We wrote an extension method for the Page (called JSStartupScript) that helps with registering the startup scripts and at the end of the day our code looks like the following:

    <%
       Page.JSStartupScript(string.Format("initFeatureX({0}, {1}, {2});",
          AntiXss.JavaScriptEncode(ViewData.Property1),
          AntiXss.JavaScriptEncode(ViewData.Property2),
          AntiXss.JavaScriptEncode(ViewData.Property3)));
    %>
    

    This also works great in combination with the ScriptManagers CompositeScript collection and LoadScriptsBeforeUI = false setting.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I know there are similar post to this but I couldn't find my answer
I know there are many threads that talk about this problem but I don't
I know there is a lot on this topic but I can't get any
I know there is a wiki page about it , but since I'm very
I know there are a lot of questions around on this subject, but I've
I know there are dozens of questions that ask about this error, but none
I know there are actually a number of questions similar to this one, but
I know there are duplicates of this question, and the answer was to refactor
I know there are several question like this one but I feel I've spent
I know there are several topics out there about this, but none of them

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.