writing asp variabls within javascript blocks

  • Thread starter Thread starter Darrel
  • Start date Start date
D

Darrel

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

example:

<script language="JavaScript">
myJavascriptVariable= <asp:Literal Runat="server"
ID="ltl_sectionsJavascriptVariables"></asp:Literal>;
</script>

ASP.net doesn't like that syntax.

-Darrel
 
hi

use this way ....

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

Thanks
Munawar
 
Hi,
Well, that's a pain. Isn't javascript supposed to be client side? Why stick
it in the codebehind?

Thanks, though!

-Darrel

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.

HTH,
Laurent
 

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. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top