ASP.NET Question

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
 
K

Ken Dopierala Jr.

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.
 
L

Lucas Tam

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

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top