Solved

javascript variable on code behind

Posted on 2008-06-26
4
1,653 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
4 Comments
 
LVL 10

Accepted Solution

by:
Dxpert earned 500 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

Suggested Solutions

This article discusses how to create an extensible mechanism for linked drop downs.
This article demonstrates how to create a simple responsive confirmation dialog with Ok and Cancel buttons using HTML, CSS, jQuery and Promises
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…

830 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