locked
How to show a textbox when user clicks on a checkbox (selection list) RRS feed

  • Question

  • User731069546 posted

    I am using a selection list to display a checkbox. When user clicks on this checkbox, I want to display a textbox. So in the SelectedIndexChanged event of the checkbox, I do

    Me.txtPartNumberRevision.Visible = True

    but this event only happens when I click on the submit button I have on my form. Any help?

    Friday, March 23, 2007 11:25 AM

Answers

  • User731069546 posted

    OK, I got it working.

    Couple of things:

    1. Need to send javascript using dummy panel with a deviec specific filter. Just put a panel with a device specific after placing all your controls on the mobile form

    2. Now in the content template of this device specific, put your javascript. You need to setup a filter for your javascript device

    3. Here is the script:

    <ContentTemplate>

    <script language="javascript">

    <!--

    function ShowTxtBox(txt, chk)

    {

    if(document.getElementById(chk).checked==true)

    {

    document.getElementById(txt).style.visibility='visible';

    } else {

    document.getElementById(txt).style.visibility='hidden';

    }

    -->

    </script>

    </ContentTemplate>

    4. The txtBox that I hide/display can NOT be the mobile etxt box. I don't know why. When I tried regular webcontrol textbox, it worked. Only thing now is that one need to use another device specific to send regular webform textbox down to the mobile client. You just place a panel on a form. Add a device specific to this panel. Setup a filter for your device (isHTML32) and then put your webform textbox control.

    5. I had to use the regular webform checkbox control. I followed step 4 to pass thsi checkbox to my mobile device

    6. Now in your page load event, you need to find the textBox and checkBox controls. Once you get a handle of these control, you do:

     

    chk.Attributes.Add("onclick", "javascript:ShowTextBox('" + txt.ClientID + "','" + chk.ClientID + "')")

    where chk is my checkBox control and txt is my TextBox control.

    Now you run this and when user clicks on checkBox, the textBox will show and hide.

    Thanks to the above poster for his/her help.

    <script l<!--EndFragment--> </BODY></HTML></script> <script l<!--EndFragment--> </BODY></HTML></script>

    <CONTENTTEMPLATE> <script language=javascript> <!-- function Testing(txt) { alert(txt); return(false); } --> </script> <script language=javascript> <!-- function MyFocus(txt, chk) { if(document.getElementById(chk).checked == true) { document.getElementById(txt).style.visibility='visible'; } else document.getElementById(txt).style.visibility='hidden'; } --> </script>  <CONTENTTEMPLATE> <script language=javascript> <!-- function Testing(txt) { alert(txt); return(false); } --> </script> <script language=javascript> <!-- function MyFocus(txt, chk) { if(document.getElementById(chk).checked == true) { document.getElementById(txt).style.visibility='visible'; } else document.getElementById(txt).style.visibility='hidden'; } --> </script> </CONTENTTEMPLATE></CONTENTTEMPLATE>

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Thursday, March 29, 2007 5:25 PM

All replies

  • User1485238302 posted

    In page load event in aspx.cs file, do this:

    chkBox1.Attributes.Add("onclick", "javascript: showTxtBox('" + txtBox1.ClientID + "','" + chkBox1.ClientID + "')");

    Then in aspx file. write a function:

    function showTxtBox(txt, chk)

    {

        if(document.getElementById(chk).checked == true)

       {

            

    document.getElementById(txt).style.visibility = 'visible';

       } 

    Also, do not set the visible property of the textbox in designer. If you want it to be hidden initially, in aspx file, where you have your html for asp:TextBox, write like this:

    <asp:TextBox runat="server" id=txtBox1 style="visibility:'hidden'">

     

    good luck

    bullpit

    Friday, March 23, 2007 3:50 PM
  • User731069546 posted

    How do I get the attribute of a mobile control?

    The checkbox that I am using is basically a selection list mobile control. It seems this control doesn't do postback.

    Friday, March 23, 2007 4:19 PM
  • User731069546 posted

    OK, I got it working.

    Couple of things:

    1. Need to send javascript using dummy panel with a deviec specific filter. Just put a panel with a device specific after placing all your controls on the mobile form

    2. Now in the content template of this device specific, put your javascript. You need to setup a filter for your javascript device

    3. Here is the script:

    <ContentTemplate>

    <script language="javascript">

    <!--

    function ShowTxtBox(txt, chk)

    {

    if(document.getElementById(chk).checked==true)

    {

    document.getElementById(txt).style.visibility='visible';

    } else {

    document.getElementById(txt).style.visibility='hidden';

    }

    -->

    </script>

    </ContentTemplate>

    4. The txtBox that I hide/display can NOT be the mobile etxt box. I don't know why. When I tried regular webcontrol textbox, it worked. Only thing now is that one need to use another device specific to send regular webform textbox down to the mobile client. You just place a panel on a form. Add a device specific to this panel. Setup a filter for your device (isHTML32) and then put your webform textbox control.

    5. I had to use the regular webform checkbox control. I followed step 4 to pass thsi checkbox to my mobile device

    6. Now in your page load event, you need to find the textBox and checkBox controls. Once you get a handle of these control, you do:

     

    chk.Attributes.Add("onclick", "javascript:ShowTextBox('" + txt.ClientID + "','" + chk.ClientID + "')")

    where chk is my checkBox control and txt is my TextBox control.

    Now you run this and when user clicks on checkBox, the textBox will show and hide.

    Thanks to the above poster for his/her help.

    <script l<!--EndFragment--> </BODY></HTML></script> <script l<!--EndFragment--> </BODY></HTML></script>

    <CONTENTTEMPLATE> <script language=javascript> <!-- function Testing(txt) { alert(txt); return(false); } --> </script> <script language=javascript> <!-- function MyFocus(txt, chk) { if(document.getElementById(chk).checked == true) { document.getElementById(txt).style.visibility='visible'; } else document.getElementById(txt).style.visibility='hidden'; } --> </script>  <CONTENTTEMPLATE> <script language=javascript> <!-- function Testing(txt) { alert(txt); return(false); } --> </script> <script language=javascript> <!-- function MyFocus(txt, chk) { if(document.getElementById(chk).checked == true) { document.getElementById(txt).style.visibility='visible'; } else document.getElementById(txt).style.visibility='hidden'; } --> </script> </CONTENTTEMPLATE></CONTENTTEMPLATE>

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Thursday, March 29, 2007 5:25 PM
  • User731069546 posted

    Hi,

     One last thing, I don't have to use a regulat webform TextBox. I can use mobile textbox and I can successfully hide/display the text box. Thanks bullpit.

    Thursday, March 29, 2007 6:21 PM