[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 243
  • 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
Sammy AgeilCommented:
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");

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

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