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

.NET accessing and setting a DetailsView hidden textbox in JavaScript


Please tell me how to access the DetailsView hiddentext box in my javascript function below:

function setcheckboxvalidate(){

CheckBox cb11 = document.getElementByID("cb1") ;

 if(cb11.Checked)  DetailsView1.hiddentextbox1="true"
else  DetailsView1.hiddentextbox1=null


In my code behind I have this for the checkbox: ( have not tested the cb1.ClientID? which is new to me?)

CheckBox cb1 = (CheckBox) DetailsView1.FindControl("CheckBox1");
cb1.Attributes.Add("OnClick", "javascript:setcheckboxvalidate('" + cb1.ClientID + "');");

Thank you for any and all input here!!!!!!

1 Solution
change CheckBox cb11 = document.getElementByID("cb1") ; to var cb11 = document.getElementById("cb1");

Note: Javascript is case sensitive and you have getElementByID instead of getElementById

The ClientID is the ID created by asp.net when the control is served to the client "Browser"
if you create a textbox and call it textbox2, once you serve the page to the client, it will be served as <input name="TextBox2" type="text" id="TextBox2" />

RSSIAdminAuthor Commented:
sammy1971...... Great before I give an A

Please..... show me the correct way to do the following as it relates to setting the value of the DetailsView1.hiddentextbox1????  will this work:

if(cb11.Checked)  DetailsView1.hiddentextbox1="true"
else  DetailsView1.hiddentextbox1=null

I am assuming is similar to var cb11 = document.getElementById("cb1");
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

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