Access a javescript var from codebehind
-
First, I have a var in java script I need to access in my c# code. How do I do this? Second, I use a droplist in another frame. I want to use the var from the jave script to be used to locate the associated selected index. What I have is the variable name and what I need is its index (I think. I then want to display the field in the droplist box and retrieve all assocated records. Thanks Brian
-
First, I have a var in java script I need to access in my c# code. How do I do this? Second, I use a droplist in another frame. I want to use the var from the jave script to be used to locate the associated selected index. What I have is the variable name and what I need is its index (I think. I then want to display the field in the droplist box and retrieve all assocated records. Thanks Brian
-
Put the variable into a Hidden Field, and after postback you can retreive it using :
Request.Form["hiddenField"]
Gidon -
Sounds like a solution. Being a neophyte I need more direction. For example I have JS function function getSomething(); { var Info = getName(); } the var Info is what I need in my c# code. So how do I put the car into a hidden field? Thanks Brian
Hi Brian, First of all you have to make your hidden field:
<input name="varInfo" id="varInfo" type="hidden">
To write to this field via javascript you can use the following code:document.getElementById("varInfo").value = "something";
ordocument.all["varInfo"].value = "something";
to get info from this field:alert(document.getElementById("varInfo").value)
oralert(document.all["varInfo"].value)
And now to read the value in your C# code after postback you simple do: C#string varInfo = Request.Form["varInfo"];
VB.NETdim varInfo as string = Request.Form(“varInfo”)
Hope this helps you, Regards, Gidon