Click here to Skip to main content
15,868,051 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
In have a master page and a content placeholder page. In the placeholder page, I have Checkbox.
If I tick the checkbox I want the RadioButtonList6 to be displayed. In following code it is not happenning in such circumstance with a master page. If run without a master page, this same code works fine. How to rectify this?
XML
<%@ Page Language="C#" MasterPageFile="~/MasterPage.master" AutoEventWireup="true" CodeFile="checkboxtest6.aspx.cs" Inherits="checkboxtest6" Title="Untitled Page" %>
<asp:Content ID="Content1" ContentPlaceHolderID="head" Runat="Server">
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" Runat="Server">
<asp:UpdatePanel ID="UP1" runat="server"  >
<ContentTemplate>
<asp:TextBox ID="MyFirstTextBox" runat="server"></asp:TextBox>
<asp:TextBox ID="MySecondTextBox" runat="server"></asp:TextBox>
<asp:CheckBox ID="MyCheckBox" runat="server"   style="  margin-left:3px; "/>
<asp:RadioButtonList ID="RBL6" runat="server" OnSelectedIndexChanged="RBL6_OSIC"
                    RepeatDirection="Vertical"  AutoPostBack="true"
                    style="" >
                    <asp:ListItem>Deliver at the above address</asp:ListItem>
                    <asp:ListItem>Deliver at a different address</asp:ListItem>
</asp:RadioButtonList>
<script type="text/javascript" language="javascript">
    function ShowRBL6() {
    RBL6.style.display ="";
}
</script>
</ContentTemplate>
</asp:UpdatePanel>
</asp:Content>


C#
public partial class checkboxtest6 : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        this.RBL6.Style.Add("display", "none");
        this.MyCheckBox.Attributes.Add("onClick", "ShowRBL6()");
    }
    protected void RBL6_OSIC(object sender, EventArgs e)// delivery options when 'send to guest' selected
    {
    }
Posted
Comments
JoCodes 29-Dec-13 10:26am    
Change the javascript method ShowRBL6()
document.getElementById("RBL6").style.display = 'none'; for hiding
and document.getElementById("RBL6").style.display = ""; for showing instead of RBL6.style.display ="";
S.Rajendran from Coimbatore 29-Dec-13 11:10am    
As told by you, I did. Not working. I did like this;
<script type="text/javascript" language="javascript">
function ShowRBL6() {
document.getElementById("RBL6").style.display = "";
}
</script>

protected void Page_Load(object sender, EventArgs e)
{
this.RBL6.Style.Add("display", "none");
this.MyCheckBox.Attributes.Add("onClick", "ShowRBL6()");

}
JoCodes 29-Dec-13 11:41am    
try with document.getElementById('<% = RBL6.ClientID %>'). Also , change your onClick to onclick .
JoCodes 29-Dec-13 12:25pm    
Below can be tried
function ShowRBL6() {
if (document.getElementById('<% = MyCheckBox.ClientID %>').checked == true)
document.getElementById('<% = RBL6.ClientID %>').style.display = "block";
else
document.getElementById('<% = RBL6.ClientID %>').style.display = "none";
so the next click will be also for unchecking will be handled.
}
S.Rajendran from Coimbatore 29-Dec-13 20:43pm    
Well. I used the line 'document.getElementById('<% = RBL6.ClientID %>').style.display = "block";'
It works. Thanks. But if I use:
if (document.getElementById('<% = MyCheckBox.ClientID %>').checked == true)
document.getElementById('<% = RBL6.ClientID %>').style.display = "block";
else
document.getElementById('<% = RBL6.ClientID %>').style.display = "none";

}
it is not working. I hope something has to be done at 'if (document.getElementById('<% = MyCheckBox.ClientID %>').checked == true)' with regard to '.checked'.

1 solution

Posting as a solution here so others can use it.
XML
function ShowRBL6() {
            if (document.getElementById('<% = MyCheckBox.ClientID %>').checked == true)
                document.getElementById('<% = RBL6.ClientID %>').style.display = "block";
            else
                document.getElementById('<% = RBL6.ClientID %>').style.display = "none";

        }

so the next click will be also for unchecking will be handled.
 
Share this answer
 
Comments
S.Rajendran from Coimbatore 30-Dec-13 4:43am    
Previously, for Checkbox we use '.checked' and 'onClick' in client side. Like that what is for RBL6. In RBL6 , I have 2 items (a,b). If 'a' is selected I want to show 'Panel1'. If 'b' is selected I want to hide 'Panel1'. This Panel1 is in separate <div>.I used the following code :
<script type="text/javascript" language="javascript">
function ShowAddressOrGuestPanel() {

if (document.getElementById('<% = Radiobuttonlist6.ClientID %>').checked == 'a')
document.getElementById('<% = Panel1.ClientID %>').style.display = "block";
else
document.getElementById('<% =Panel1.ClientID %>').style.display = "none";
}
</script

this.Radiobuttonlist6.Attributes.Add("onClick", "ShowAddressOrGuestPanel()");

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