Telerik is a leading vendor of ASP.NET AJAX, ASP.NET MVC, Silverlight, WinForms and WPF controls and components, as well as .NET Reporting, .NET ORM , .NET CMS, Code Analysis, Mocking, Team Productivity and Automated Testing Tools. Building on its expertise in interface development and Microsoft technologies, Telerik helps customers build applications with unparalleled richness, responsiveness and interactivity. Telerik products help thousands of companies to be more productive and deliver reliable applications under budget and on time.
Version Q2 2011 released 07/12/2011
select

Ajax / Show/Hide Web Controls

Show/hide web controls
RadControls


Form controls




  • It is a common scenario for ASP.NET applications to show/hide controls as a result of user interaction or some event.

    You can have the same functionality with RadAjaxManager or RadAjaxPanel as well but should have the following in mind - RadAjaxManager relies on the HTML output of controls to be updated, that's why you need to put the control that should be updated in an always visible container like ASP Panel. Then set in the RadAjaxManager the AJAX pairs where the AJAX initiator control should update the ASP Panel. In the code-behind set the Visible property of the control that should be shown/hidden to true or false accordingly.

Source Code

C# VB.NET
Show code in new window Demo isolation steps
  • <%@ Page Language="vb" CodeFile="DefaultVB.aspx.vb" Inherits="Telerik.AJAXExamplesVBNET.AJAX.Examples.Functionality.ShowingWebControls.DefaultVB" %>

    <%@ Register TagPrefix="telerik" TagName="Footer" Src="~/Common/Footer.ascx" %>
    <%@ Register TagPrefix="telerik" TagName="HeadTag" Src="~/Common/HeadTag.ascx" %>
    <%@ Register TagPrefix="telerik" TagName="Header" Src="~/Common/Header.ascx" %>
    <%@ Register TagPrefix="telerik" Namespace="Telerik.Web.UI" Assembly="Telerik.Web.UI" %>
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/tr/xhtml11/DTD/xhtml11.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head runat="server">
        <telerik:HeadTag ID="Headtag1" runat="server"></telerik:HeadTag>
    </head>
    <body class="BODY">
        <form id="mainForm" method="post" runat="server">
        <telerik:Header ID="Header1" runat="server" NavigationLanguage="VB" ShowSkinChooser="true" />
        <telerik:RadScriptManager ID="RadScriptManager1" runat="server">
        </telerik:RadScriptManager>
        <telerik:RadFormDecorator ID="RadFormDecorator1" runat="server" />
        <telerik:RadAjaxManager ID="RadAjaxManager1" runat="server">
            <AjaxSettings>
                <telerik:AjaxSetting AjaxControlID="rbListRadControls">
                    <UpdatedControls>
                        <telerik:AjaxUpdatedControl ControlID="rbListRadControls" />
                        <telerik:AjaxUpdatedControl ControlID="Panel1" LoadingPanelID="RadAjaxLoadingPanel1" />
                    </UpdatedControls>
                </telerik:AjaxSetting>
                <telerik:AjaxSetting AjaxControlID="rbListFormControls">
                    <UpdatedControls>
                        <telerik:AjaxUpdatedControl ControlID="rbListFormControls" />
                        <telerik:AjaxUpdatedControl ControlID="Panel1" LoadingPanelID="RadAjaxLoadingPanel1" />
                    </UpdatedControls>
                </telerik:AjaxSetting>
                <telerik:AjaxSetting AjaxControlID="btnPostback">
                    <UpdatedControls>
                        <telerik:AjaxUpdatedControl ControlID="lblMessage" LoadingPanelID="RadAjaxLoadingPanel1" />
                    </UpdatedControls>
                </telerik:AjaxSetting>
                <telerik:AjaxSetting AjaxControlID="chkBoxListCountries">
                    <UpdatedControls>
                        <telerik:AjaxUpdatedControl ControlID="lblMessage" LoadingPanelID="RadAjaxLoadingPanel1" />
                    </UpdatedControls>
                </telerik:AjaxSetting>
                <telerik:AjaxSetting AjaxControlID="ddlContinents">
                    <UpdatedControls>
                        <telerik:AjaxUpdatedControl ControlID="lblMessage" LoadingPanelID="RadAjaxLoadingPanel1" />
                    </UpdatedControls>
                </telerik:AjaxSetting>
                <telerik:AjaxSetting AjaxControlID="RadCalendar1">
                    <UpdatedControls>
                        <telerik:AjaxUpdatedControl ControlID="lblMessage" LoadingPanelID="RadAjaxLoadingPanel1" />
                    </UpdatedControls>
                </telerik:AjaxSetting>
                <telerik:AjaxSetting AjaxControlID="RadPanelBar1">
                    <UpdatedControls>
                        <telerik:AjaxUpdatedControl ControlID="lblMessage" LoadingPanelID="RadAjaxLoadingPanel1" />
                    </UpdatedControls>
                </telerik:AjaxSetting>
                <telerik:AjaxSetting AjaxControlID="RadTreeView1">
                    <UpdatedControls>
                        <telerik:AjaxUpdatedControl ControlID="lblMessage" LoadingPanelID="RadAjaxLoadingPanel1" />
                    </UpdatedControls>
                </telerik:AjaxSetting>
            </AjaxSettings>
        </telerik:RadAjaxManager>
        <telerik:RadAjaxLoadingPanel ID="RadAjaxLoadingPanel1" runat="server" />
        <fieldset>
            <legend>Show/hide web controls</legend>
            <dl>
                <dt></dt>
                <dd>
                    <table cellspacing="11" summary="" style="height: 400px;">
                        <tr>
                            <td style="width: 206px">
                                <span>RadControls</span>
                                <br />
                                <br />
                                <asp:RadioButtonList ID="rbListRadControls" runat="server" AutoPostBack="True">
                                    <asp:ListItem Value="RadCalendar">RadCalendar</asp:ListItem>
                                    <asp:ListItem Value="RadPanelBar">RadPanelBar</asp:ListItem>
                                    <asp:ListItem Value="RadTreeView">RadTreeView</asp:ListItem>
                                </asp:RadioButtonList>
                                <br />
                                <span>Form controls</span>
                                <br />
                                <br />
                                <asp:RadioButtonList ID="rbListFormControls" runat="server" AutoPostBack="True">
                                    <asp:ListItem Value="Button">Button</asp:ListItem>
                                    <asp:ListItem Value="CheckBoxList">CheckBoxList</asp:ListItem>
                                    <asp:ListItem Value="DropDownList">DropDownList</asp:ListItem>
                                </asp:RadioButtonList>
                            </td>
                            <td style="height: 230px; vertical-align: top;">
                                <asp:Panel ID="Panel1" runat="server">
                                    <table>
                                        <tr>
                                            <td style="height: 100px; vertical-align: top;">
                                                <telerik:RadCalendar ID="RadCalendar1" runat="server" EnableMultiSelect="false" Visible="false"
                                                    AutoPostBack="true" />
                                                <telerik:RadPanelBar ID="RadPanelBar1" runat="server" Visible="false">
                                                    <Items>
                                                        <telerik:RadPanelItem Text="Mail" Expanded="True">
                                                            <Items>
                                                                <telerik:RadPanelItem Text="Personal Folders">
                                                                </telerik:RadPanelItem>
                                                                <telerik:RadPanelItem Text="Deleted Items">
                                                                </telerik:RadPanelItem>
                                                                <telerik:RadPanelItem Text="Inbox">
                                                                </telerik:RadPanelItem>
                                                            </Items>
                                                        </telerik:RadPanelItem>
                                                        <telerik:RadPanelItem Text="Contacts">
                                                            <Items>
                                                                <telerik:RadPanelItem Text="My Contacts">
                                                                </telerik:RadPanelItem>
                                                                <telerik:RadPanelItem Text="Address Cards">
                                                                </telerik:RadPanelItem>
                                                                <telerik:RadPanelItem Text="Phone List">
                                                                </telerik:RadPanelItem>
                                                                <telerik:RadPanelItem Text="Shared Contacts">
                                                                </telerik:RadPanelItem>
                                                            </Items>
                                                        </telerik:RadPanelItem>
                                                        <telerik:RadPanelItem Text="Tasks">
                                                            <Items>
                                                                <telerik:RadPanelItem Text="My Tasks">
                                                                </telerik:RadPanelItem>
                                                                <telerik:RadPanelItem Text="Shared Tasks">
                                                                </telerik:RadPanelItem>
                                                                <telerik:RadPanelItem Text="Active Tasks">
                                                                </telerik:RadPanelItem>
                                                                <telerik:RadPanelItem Text="Completed Tasks">
                                                                </telerik:RadPanelItem>
                                                            </Items>
                                                        </telerik:RadPanelItem>
                                                        <telerik:RadPanelItem Text="Notes">
                                                            <Items>
                                                                <telerik:RadPanelItem Text="My Notes">
                                                                </telerik:RadPanelItem>
                                                                <telerik:RadPanelItem Text="Notes List">
                                                                </telerik:RadPanelItem>
                                                                <telerik:RadPanelItem Text="Shared Notes">
                                                                </telerik:RadPanelItem>
                                                                <telerik:RadPanelItem Text="Archive">
                                                                </telerik:RadPanelItem>
                                                            </Items>
                                                        </telerik:RadPanelItem>
                                                        <telerik:RadPanelItem Text="Folders List">
                                                            <Items>
                                                                <telerik:RadPanelItem Text="My Client.Net">
                                                                </telerik:RadPanelItem>
                                                                <telerik:RadPanelItem Text="My Profile">
                                                                </telerik:RadPanelItem>
                                                                <telerik:RadPanelItem Text="My Support Tickets">
                                                                </telerik:RadPanelItem>
                                                                <telerik:RadPanelItem Text="My Licenses">
                                                                </telerik:RadPanelItem>
                                                            </Items>
                                                        </telerik:RadPanelItem>
                                                    </Items>
                                                </telerik:RadPanelBar>
                                                <telerik:RadTreeView ID="RadTreeView1" runat="server" AccessKey="T" Visible="false">
                                                    <Nodes>
                                                        <telerik:RadTreeNode Text="Books" Expanded="true">
                                                            <Nodes>
                                                                <telerik:RadTreeNode Text="Arts" />
                                                                <telerik:RadTreeNode Text="Biographies" />
                                                                <telerik:RadTreeNode Text="Cooking" />
                                                                <telerik:RadTreeNode Text="History" />
                                                                <telerik:RadTreeNode Text="Mystery" />
                                                                <telerik:RadTreeNode Text="Romance" />
                                                                <telerik:RadTreeNode Text="Science Fiction " />
                                                            </Nodes>
                                                        </telerik:RadTreeNode>
                                                        <telerik:RadTreeNode Text="Music">
                                                            <Nodes>
                                                                <telerik:RadTreeNode Text="Alternative" />
                                                                <telerik:RadTreeNode Text="Classical" />
                                                                <telerik:RadTreeNode Text="Dance" />
                                                                <telerik:RadTreeNode Text="Folk " />
                                                                <telerik:RadTreeNode Text="Hard Rock" />
                                                                <telerik:RadTreeNode Text="Jazz" />
                                                            </Nodes>
                                                        </telerik:RadTreeNode>
                                                        <telerik:RadTreeNode Text="Movies">
                                                            <Nodes>
                                                                <telerik:RadTreeNode Text="Action" />
                                                                <telerik:RadTreeNode Text="Animation" />
                                                                <telerik:RadTreeNode Text="Classics" />
                                                                <telerik:RadTreeNode Text="Comedy" />
                                                                <telerik:RadTreeNode Text="Documentary" />
                                                                <telerik:RadTreeNode Text="Drama" />
                                                                <telerik:RadTreeNode Text="Horror" />
                                                                <telerik:RadTreeNode Text="Mystery" />
                                                            </Nodes>
                                                        </telerik:RadTreeNode>
                                                        <telerik:RadTreeNode Text="Software">
                                                            <Nodes>
                                                                <telerik:RadTreeNode Text="Database" />
                                                                <telerik:RadTreeNode Text="Networking" />
                                                                <telerik:RadTreeNode Text="Presentation" />
                                                                <telerik:RadTreeNode Text="Project Management" />
                                                                <telerik:RadTreeNode Text="Reports" />
                                                                <telerik:RadTreeNode Text="Spreadsheet" />
                                                                <telerik:RadTreeNode Text="Word Processing" />
                                                            </Nodes>
                                                        </telerik:RadTreeNode>
                                                    </Nodes>
                                                </telerik:RadTreeView>
                                            </td>
                                        </tr>
                                        <tr>
                                            <td style="height: 50%">
                                                <asp:Button ID="btnPostback" runat="server" Visible="False" Text="Submit" OnClick="btnPostback_Click" />
    <asp:CheckBoxList ID="chkBoxListCountries" runat="server" AutoPostBack="True" Height="31px"
    Width="76px" Visible="False">

                                                    <asp:ListItem Value="item 1">England</asp:ListItem>
                                                    <asp:ListItem Value="item 2">USA</asp:ListItem>
                                                    <asp:ListItem Value="item 3">Holland</asp:ListItem>
                                                </asp:CheckBoxList>
    <asp:DropDownList ID="ddlContinents" runat="server" AutoPostBack="True" Width="84px"
    Visible="False">

                                                    <asp:ListItem Value="Asia">Asia</asp:ListItem>
                                                    <asp:ListItem Value="America">America</asp:ListItem>
                                                    <asp:ListItem Value="Europe">Europe</asp:ListItem>
                                                    <asp:ListItem Value="Africa">Africa</asp:ListItem>
                                                </asp:DropDownList>
                                            </td>
                                        </tr>
                                    </table>
                                    <br />
                                    <br />
                                </asp:Panel>
                                <asp:Label ID="lblMessage" runat="server" />
                            </td>
                        </tr>
                    </table>
                </dd>
            </dl>
        </fieldset>
        <!-- content end -->
        <telerik:Footer ID="Footer1" runat="server"></telerik:Footer>
        </form>
    </body>
    </html>

Get more than expected!

 
 

Take your time to truly experience the power of RadControls for ASP.NET AJAX with a free 60-day trial backed up by Telerik’s unlimited dedicated support.

Download your RadControls for ASP.NET AJAX trial and jumpstart your development with the available Getting Started resources.

If you have any questions, do not hesitate to contact us at sales@telerik.com.

Copyright 2002-2024 © Telerik. All right reserved
Telerik Inc, 201 Jones Rd, Waltham, MA 02451