ASP.NET Question

  • Thread starter Thread starter Roshawn Dawson
  • Start date Start date
R

Roshawn Dawson

Hi,

I'm a newbie to web programming, let alone ASP.NET. However, I have a
few questions.

Can variables declared in Javascript be accessible to code contained in
other script blocks (ie. <script runat="server"
language="c#">...</script>) and vice versa? If so, how?

Does code contained in script blocks or <% %> tags cause postbacks to
the server?

Thanks,
Roshawn
 
Hi Roshawn,

Not directly. You need to assign the variable to a hidden field with the
runat="server" attribute set:

<input type="hidden" id="hidValue" name="hidValue" runat="server">

Then use Javascript to assign the variable you want the server side code to
access to the hidden field:

document.getElementById("hidValue").value = jsvariable;

Then, when you are in the server code you can retrieve the value by
referencing hidValue.Value. Good luck! Ken.
 
Can variables declared in Javascript be accessible to code contained in
other script blocks (ie. <script runat="server"
language="c#">...</script>) and vice versa? If so, how?

No, you cannot access Javascript variables. Javascript runs within the web
browser, ASP.NET on the server side. However, there are ways to pass data
back and forth (with Javascript Remoting or via form variables)
Does code contained in script blocks or <% %> tags cause postbacks to
the server?

The script doesn't cause postbacks... but rather a user action triggers a
postback.
 

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