writing asp variabls within javascript blocks

Discussion in 'ASP .Net' started by Darrel, May 24, 2006.

  1. Darrel

    Darrel Guest

    In asp.net 1.1, what is the proper method for writing variables to the aspx
    page that are contained within javascript blocks?


    <script language="JavaScript">
    myJavascriptVariable= <asp:Literal Runat="server"

    ASP.net doesn't like that syntax.

    Darrel, May 24, 2006
    1. Advertisements

  2. Patrick.O.Ige, May 24, 2006
    1. Advertisements

  3. Darrel

    Darrel Guest

    RegisterClientScriptBlock & RegisterStartupScript
    Well, that's a pain. Isn't javascript supposed to be client side? Why stick
    it in the codebehind?

    Thanks, though!

    Darrel, May 24, 2006
  4. Darrel

    MS Guest


    use this way ....

    <script language="JavaScript">
    myJavascriptVariable= <% = serverVariable %>;

    MS, May 26, 2006
  5. Hi,
    I don't get your question.

    JavaScript is client-side, but some part of your scripts might depend on
    server-side variables. What I do is create JS files with the "pure
    client-side code". However, some parts of the code must be created
    dynamically on the server (typical example: localized texts), so I add
    script lines using RegisterClientScriptBlock.

    Eventually, every piece of script added to the page is interpreted and
    can be referenced from other piece of script on the same page.

    Laurent Bugnion, May 28, 2006
    1. Advertisements

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.