Solved

javascript variable on code behind

Posted on 2008-06-26
4
1,627 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
Comment Utility
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
Comment Utility
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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Just a quick little trick I learned recently.  Now that I'm using jQuery with abandon in my asp.net applications, I have grown tired of the following syntax:      (CODE) I suppose it just offends my sense of decency to put inline VBScript on a…
This article will give core knowledge of JavaScript and will head in to your first JavaScript program. I am Durvesh Naik and I am here to deal with this series of JavaScript. I will teach you JavaScript in part wise , as its quite boring to read big…
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…

772 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

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now