Click here to Skip to main content
15,892,072 members
Please Sign up or sign in to vote.
5.00/5 (1 vote)
See more:
Actually i am having two text boxes in one panel which is in formview1 and checkbox is also in formview1 when i check the check box it should display the panel uncheck means it should hide the panel this functionality i am doing in .cs page in checkbox_checked event but now i dont want to postback for this .so i need javascript code for this

//below is my code
XML
<asp:CheckBox ID="chkReceiveMobileNotification" runat="server"   Enabled="true"
                                                          oncheckedchanged="chkReceiveMobileNotification_CheckedChanged"
                                                          AutoPostBack="True"  />
                                                  </div>
                                                  <asp:Panel ID="PanelEnableMobileNotifications" runat="server">
                                                  <div class="sepH_b">
                                                <label for="Allergen" class="lbl_a"  style="width:300px">Mobile Notification Time Range</label>
                                                   <asp:TextBox ID="txtMobilNotMin" runat="server" CssClass="inpt_a" Text='<%# Bind("NotifTime") %>' />
                                                </div>

                                                <div class="sepH_b">
                                                <label for="Allergen" class="lbl_a"  style="width:300px">Mobile Notification Count</label>
                                                   <asp:TextBox ID="txtMobilNotCount" runat="server" CssClass="inpt_a" Text='<%# Bind("NotifCount") %>' />
                                                </div>
                                                </asp:Panel>
Posted

1 solution

Hi Ntitish,

Please refer to the below link for doing it using jQuery.
jsfiddle[^]

This is done in jQuery and can also be done in JavaScript. Let me know if you are only into JS.

XML
<script>
    function hideshow(obj) {
        if (obj.checked) {
            alert('hide');
            document.getElementById('<%=PanelEnableMobileNotifications.ClientID %>').style.display = 'none';
        }
        else {
            alert('show');
            document.getElementById('<%=PanelEnableMobileNotifications.ClientID %>').style.display = 'inline';
        }
    }
</script>


And the HTML checkbox code looks like the below

ASP.NET
<asp:CheckBox ID="chkReceiveMobileNotification" runat="server"   Enabled="true" onclick="hideshow(this)"  />


Thank you,
Vamsi
 
Share this answer
 
v3
Comments
ntitish 24-May-13 5:59am    
any thing i need out-put can u provide me code for the above code....
RelicV 24-May-13 6:14am    
I've added new code to my solution. Please check the Javascript code. Thnx.
ntitish 24-May-13 6:27am    
thanks sir and i had one more problem in my above code i am using two text boxes, now in the place of that i am using two combo boxes..now what was my problem is if the check box is checked means i want to apply the required field validators to that two combo boxes other wise if i uncheck the check box means the validations to that two combo boxes should be false for that java script possible ha sir...
RelicV 24-May-13 6:48am    
I think you need to look here for more answers on this. http://forums.asp.net/t/1460834.aspx/1

Its possible. You need to get the 'ControlToValidate' attribute of both the validators and set them to their respective control IDs if checkbox is checked or else set them to empty strings in JS. Refer the link pls.
ntitish 24-May-13 6:30am    
Compiler Error Message: CS0103: The name 'PanelEnableMobileNotifications' does not exist in the current context

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900