?
Solved

javascript variable on code behind

Posted on 2008-06-26
4
Medium Priority
?
1,666 Views
Last Modified: 2008-11-27
I have a variable named 'timeoutlocation' defined in an external JS file.
I need to assign a different value to this 'timeoutlocation' variable on code behind page.

How can I access a external JS variable on .aspx.cs page??
Would appreciate any help in the code.
0
Comment
Question by:newaspdotnet
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
4 Comments
 
LVL 10

Accepted Solution

by:
Dxpert earned 2000 total points
ID: 21878653
Get that variable out of the external JS and place it on the ASPX page (front end). Then declare a public variable on the code behind page then set its value on Page_Load.

On the ASPX page do this use <%=%> to print the value from the public variable set on the code behind.

pseudo code:

javascript code...

var timeoutlocation = <%=NewVariableFromCodeBehide%>

end javascript code...


0
 
LVL 16

Expert Comment

by:ororiole
ID: 21878715
You have to include your external js file on the page obviously. Then you define a hidden field on your page, place the value in it from the code behind.

Inside a js function get the hidden field and set your variable to its value. Tog et an aspx control use the following syntax:

function SetTimeoutLocation()
{
   timeoutlocation = document.GetElementById('<%=hiddenField1.ClientID%>').value;
}
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
Originally, this post was published on Monitis Blog, you can check it here . In business circles, we sometimes hear that today is the “age of the customer.” And so it is. Thanks to the enormous advances over the past few years in consumer techno…
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

752 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question