We help IT Professionals succeed at work.
Get Started

Using Javascript to Show/Hide a control inside of an ASCX control

Last Modified: 2012-05-09
I am trying to show or hide a control that is inside an ASCX control from the content page the control is on.

I have a list box and want to show/hide a calendar control based on the selection of the list box.
The difficulty I am having is getting the id of the control withing the ASCX control. Also, I don't know
if it matters but this is also a content page of a master page. The first code snippet is the ASP.NET
code for my page. The second code snippet is the ASP.NET code for the ASCX control.
What I need is the Javascript that would go in the ASPX page (first code snippet) to make this work.
I've hunted all over the internet and just cannot find how to code this properly. I have tried variation
of "var control = document.getElementByID("ControIDName");" But this has not worked for me.
Let me know if you need any other information.

<%@ Page Language="vb" AutoEventWireup="false" MasterPageFile="~/MasterPageReports.master"
    CodeBehind="MenuClientReports.aspx.vb" Inherits="MARS3_VBNET.WebForm3" Title="Client Reports"  %>

<%@ MasterType VirtualPath="~/MasterPageReports.master" %>
<%@ Register Src="CustomControls/ReportOptions.ascx" TagName="ReportOptions" TagPrefix="uc1" %>
<asp:Content ID="Content1" ContentPlaceHolderID="head" runat="server">
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" runat="server">
    <asp:UpdatePanel ID="UpdatePanel1" runat="server">
            <asp:Panel ID="Panel1" runat="server" BorderStyle="Solid" BorderWidth="2px" HorizontalAlign="Left">
                        <td align="center">
                            <br />
                            <asp:Label ID="lblSelectReport" runat="server" Text="Select Report" Width="124px"
                                Font-Bold="True" Font-Underline="True"></asp:Label>
                        <td valign="top" align="center">
                            <asp:RadioButtonList ID="ClientReportsRadioButtonList" runat="server" Width="250px"
                                Style="text-align: left" AutoPostBack="True">
                                <asp:ListItem Value="0">Booked Orders</asp:ListItem>
                                <asp:ListItem Value="1">Open Invoices</asp:ListItem>
                                <asp:ListItem Value="2">Open Orders</asp:ListItem>
                                <asp:ListItem Value="3">Payment History</asp:ListItem>
                                <asp:ListItem Value="4">Purchasing Detail</asp:ListItem>
                                <asp:ListItem Value="5">Purchasing Summary</asp:ListItem>
                            <br />
                            <asp:Button ID="btnSubmit" runat="server" Text="Submit" CssClass="btnGradientRed"
                                Enabled="false" />
                        <td valign="top" >
                            <uc1:ReportOptions ID="ReportOptions1" runat="server" Visible="false" />
                <br />

Open in new window

Watch Question
Top Expert 2010
This problem has been solved!
Unlock 1 Answer and 48 Comments.
See Answer
Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

  • Troubleshooting
  • Research
  • Professional Opinions
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE