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

Posted on 2012-08-21
Last Modified: 2012-09-04
What I’m trying to do is when the user clicks the 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

Question by:bmanmike39
    1 Comment
    LVL 26

    Accepted Solution

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

    Open in new window

    Alan ";0)

    Featured Post

    Find Ransomware Secrets With All-Source Analysis

    Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

    Join & Write a Comment

    It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
    JavaScript can be used in a browser to change parts of a webpage dynamically. It begins with the following pattern: If condition W is true, do thing X to target Y after event Z. Below are some tips and tricks to help you get started with JavaScript …
    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…

    729 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

    22 Experts available now in Live!

    Get 1:1 Help Now