Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1675
  • Last Modified:

javascript variable on code behind

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
newaspdotnet
Asked:
newaspdotnet
1 Solution
 
DxpertCommented:
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
 
ororioleCommented:
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

Get your problem seen by more experts

Be seen. Boost your question’s priority for more expert views and faster solutions

Tackle projects and never again get stuck behind a technical roadblock.
Join Now