troubleshooting Question

Having problems either sending or receiving values from a hidden field.

Avatar of steelsanc
steelsanc asked on
24 Comments1 Solution375 ViewsLast Modified:
So, I'm fairly new to and I wanted to pass from values from a javascript function (called in code behind) to the server side.  I have the javascript function in a .js file.  Upon further research online, I found a way through hidden fields.  I declared a hidden field and the code looks like it's fine (obviously it's not) but it is still not receiving the values from the hidden field.  Can you all take a look at my code and tell me what is wrong?
code in aspx:
<asp:HiddenField ID="ContentType" runat="server" />
code behind:
public partial class _Default : System.Web.UI.Page 
    public void Page_Load(object sender, EventArgs e)
        SqlConnection con = new SqlConnection();
        con.ConnectionString = ConfigurationManager.ConnectionStrings["SalesDBConnectionString"].ToString();
        SqlDataReader read;
        SqlCommand cmdtest = new SqlCommand("SELECT * FROM Details_Instructor", con);
        cmdtest.CommandType = CommandType.Text;
        read = cmdtest.ExecuteReader();
        ArrayList myArrList = new ArrayList();
            while (read.Read())
            for (int i = 0; i <= 10; i++)
                var testString = myArrList[i].ToString();
                TextBox1.Text += (testString + '\n');
                ClientScript.RegisterClientScriptBlock(typeof(Page), "formValidation", "isValidPhoneNumber('" + testString + "', true, true)", true);
                string testHiddenField = Request.Form["ContentType"];
                TextBox3.Text += testHiddenField;
        catch (SqlException ex)
            TextBox2.Text = ex.ToString();
            TextBox3.Text += "End";
    public void Button1_Click(object sender, EventArgs e)
last part of code from the javascript file where I try to pass a value (newPhone):
        var myTextBox = document.getElementById("ContentType"); 
        myTextBox = newPhone;
Am I doing something wrong with how I assign a value to the hidden field?

Our community of experts have been thoroughly vetted for their expertise and industry experience.

Join our community to see this answer!
Unlock 1 Answer and 24 Comments.
Start Free Trial
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 24 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros