.NET Set DetailsView TextBox using Javascript

Posted on 2006-05-16
Last Modified: 2008-01-09
I have a  DetailsViews control which has a set of  5 CheckBoxes and a common hidden Textbox.

Here is my goal ( could someone show me  the code to get this done):

When any CheckBox is checked (using "onCheckedChanged") I want to set the word "true" in the common hidden TextBox.

However if none of the CheckBoxes are checked I want the hidden textbox text to be set to "null" or "" . I am using
this hidden TextBox as a means to validate if any of the checkboxes were checked.

1) I managed to call a common javascript function as follows, but don't know how to set the hidden TextBox from
within the javascript function.

if (!IsPostBack)
   CheckBox cb1 = (CheckBox) DetailsView1.FindControl("CheckBox1");
   cb1.Attributes.Add("OnClick", "javascript:setcheckboxvalidate();");
   ditto for all 5 checkboxes

function setcheckboxvalidate(){

this is where I am stuck??  I don't know how to check the status of each of the 5 checkboxes
and  set the common DetailsView1 hidden textbox " true"  if any check box is checked  or  "null" "" if none of the
checkboxes are checked.

var ctchecked1 = document.getElementById( ??????);

          if(ctchecked1)              ??hiddentextbox="true"


            <asp:TemplateField HeaderText="First Name" >
                <asp:TextBox   id="firstnametxt"
                     Runat="Server" />
                    Runat="Server" />

            <asp:TemplateField HeaderText=" chbox2" >
        <asp:CheckBox id="ckbox2" Runat="Server" />

           etc for the other 3 checkkboxes

           <asp:TextBox   id="hiddentxt"

                     Runat="Server" />

        <asp:CommandField ShowInsertButton="True"
        InsertText="Add Person" />

<asp:SqlDataSource ID="PersonSource" runat="server" ConnectionString="<%$ ConnectionStrings:Person %>"

   InsertCommand="INSERT INTO persons firstname,checkbox1Column,checkbox2Column, etc) VALUES (@firstname, @checkbox1value,@checkbox2value, etc...)" >

HELP! ( and thanks for any and all input here)
Question by:RSSIAdmin
    LVL 33

    Accepted Solution

    Do you know how to get the ClientID of these checkboxes?, it's almost required when you are in a detailsview and other databound controls.

    My suggestion would be to use the ClientID in yoursetcheckboxvalidate(); function (or somewhere else), something like this,

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

    if you view the rendered source now, you'll see check checkbox's id sent to this function where you can use document.getElementByID() to get a reference to the control in javascript.

    Hope this gets you started as to how to get at these checkbox values in javascript!

    Author Comment


    Now? please tell me how to access to access the DetailsView hiddentext box in my javascript function below.

    (I plan to have one javascript function (setcheckboxvalidate#1,#2,# etc) per each of the 5 checkboxes in my validation scheme)

    function setcheckboxvalidate#1(){

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

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



    LVL 33

    Expert Comment

    Did you figure this last question out RSSIAdmin?

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Why You Should Analyze Threat Actor TTPs

    After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

    A quick way to get a menu to work on our website, is using the Menu control and assign it to a web.sitemap using SiteMapDataSource. Example of web.sitemap file: (CODE) Sample code to add to the page menu: (CODE) Running the application, we wi…
    International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
    Hi everyone! This is Experts Exchange customer support.  This quick video will show you how to change your primary email address.  If you have any questions, then please Write a Comment below!
    Internet Business Fax to Email Made Easy - With eFax Corporate (, you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…

    761 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

    14 Experts available now in Live!

    Get 1:1 Help Now