Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

.NET Set DetailsView TextBox using Javascript

Posted on 2006-05-16
3
Medium Priority
?
1,464 Views
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:DetailsView
        DataSourceID="PersonSource"
        ID="DetailsView1"
        AutoGenerateRows="false"
        DefaultMode="Insert"
        CellPadding="5"
        HeaderText="Person"
        Runat="Server">
        <Fields>
            <asp:TemplateField HeaderText="First Name" >
            <EditItemTemplate>
                <asp:TextBox   id="firstnametxt"
                    Text='<%#Bind("firstname")%>'
                     Runat="Server" />
                <asp:RequiredFieldValidator
                    ValidationGroup="person"
                    ControlToValidate="firstname"
                    Text="(required)"
                    Runat="Server" />
            </EditItemTemplate>
            </asp:TemplateField>

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

           etc for the other 3 checkkboxes

           <asp:TextBox   id="hiddentxt"

                     Runat="Server" />



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

<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)
0
Comment
Question by:RSSIAdmin
  • 2
3 Comments
 
LVL 33

Accepted Solution

by:
raterus earned 2000 total points
ID: 16691272
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!
--Michael
0
 

Author Comment

by:RSSIAdmin
ID: 16694579
raterus.....

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

Help!!


}


0
 
LVL 33

Expert Comment

by:raterus
ID: 16698304
Did you figure this last question out RSSIAdmin?
0

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!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I have developed many web applications with asp & asp.net and to add and use a dropdownlist was always a very simple task, but with the new asp.net, setting the value is a bit tricky and its not similar to the old traditional method. So in this a…
This article discusses the ASP.NET AJAX ModalPopupExtender control. In this article we will show how to use the ModalPopupExtender control, how to display/show/call the ASP.NET AJAX ModalPopupExtender control from javascript, how to show/display/cal…
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an anti-spam), the admin…
In a question here at Experts Exchange (https://www.experts-exchange.com/questions/29062564/Adobe-acrobat-reader-DC.html), a member asked how to create a signature in Adobe Acrobat Reader DC (the free Reader product, not the paid, full Acrobat produ…
Suggested Courses
Course of the Month13 days, 9 hours left to enroll

581 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