• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 470
  • Last Modified:

How would I move a asp.net variable value, on the button click, to a JavaScript variable (asp.net C#)

What I’m trying to do is when the user clicks the asp.net button the event moves the value of the studentID variable to a JavaScritpt variable call stID to be manipulated.

I know ASP.NET,  but I don’t know Java scritp.

Thanks for any help!

This is what i have in code behind  .net:

protected void Button1_Click(object sender, EventArgs e)
        string x = "studentID";

        x = HiddenField1.Value.ToString();


Open in new window

This is my JavaScript  Code:
function notEmpty(){
	var myTextField = document.getElementById('HiddenField1');
	if (myTextField.value != "") {

	    var stID = myTextField;
	    alert("This is your js var value:" + stID.value);
	    alert("You entered: " + myTextField.value);

	    alert("Would you please enter some text?");	

Open in new window

1 Solution
Alan WarrenCommented:
Hi bmanmike39
Try something like this:
var myTextField = document.getElementById(<%=HiddenField1.ClientID %>);

Open in new window

Alan ";0)

Featured Post

Important Lessons on Recovering from Petya

In their most recent webinar, Skyport Systems explores ways to isolate and protect critical databases to keep the core of your company safe from harm.

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