Note that there are some explanatory texts on larger screens.

plurals
  1. POHow can I share a variable between my C# ASP.NET code and the HTML/JavaScript?
    primarykey
    data
    text
    <blockquote> <p><strong>Possible Duplicate:</strong><br> <a href="https://stackoverflow.com/questions/8532592/how-to-share-a-variable-between-c-sharp-and-javascript">How to share a variable between C# and JavaScript?</a> </p> </blockquote> <p>I am enhancing a C# ASP.NET web app that has two important divisions in the HTML. Two menu options are available to cause one to be hidden and the other to be unhidden. Let's call them Page One and Page Two.</p> <p>The problem is that some things on the page cause a postback, which causes a total refresh and forces the default to be Page One. Also we automatically do a refresh every five minutes to get new page content. If the user happens to be viewing Page Two when the refresh occurs either automatically or because of a postback after the user has clicked on certain things, the page automatically goes back to Page One.</p> <p>Long term the solution is to properly use AJAX. For now I need a quick and dirty way to remember which page the user is on when a refresh occurs and then put him back on that page upon refresh.</p> <p>Can I create a variable on the server side in C# that I can interrogate on the client side with JavaScript? Technically the server does not need to know which page div is displayed in the browser if I can somehow make the client remember it from page refresh to refresh. Is there a way to do that?</p> <p>Forgive me if this seems elementary. I have many years of programming experience (mostly C/C++ in the MS-DOS and Unix worlds), but not very much in the ASP.NET environment.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload