how to get the label control inside a panel

2 posts, 0 answers
  1. Bharathwajan Venkatanarayanan
    Bharathwajan Venkatanarayanan avatar
    25 posts
    Member since:
    Aug 2009

    Posted 07 Oct 2009 Link to this post

    hi,

    i want to get the lable inside a panelbar
    i have tried the following but the value is null.

    var

     

    lblEmail = document.getElementById('pnlbarRegn.FindItemByValue("AccountHolderInformation").FindControl("lblEmail").ClientID >');

     


    the client code looks like the follwoing

    my panel bar name is pnlbarRegn

    <

     

    telerik:RadPanelItem Enabled="false" Text="Step 3: Account Holder Information" runat="server"

     

     

    Font-Underline="false" FocusedCssClass="">

     

     

    <Items>

     

     

    <telerik:RadPanelItem runat="server" Value="AccountHolderInformation">

     

     

    <ItemTemplate>

     

     

    <table width="100%" border="0" cellspacing="0" cellpadding="2">

     

     

     

    <tr>

     

     

    <td align="right">

     

    Email

     

    </td>

     

     

    <td align="left">

     

     

    <telerik:RadTextBox ID="txtEmail" runat="server" Skin="" CssClass="text" MaxLength="255"

     

     

    AutoPostBack="false" onfocus="Text1_focus()">

     

     

    </telerik:RadTextBox><asp:RequiredFieldValidator ID="rfvEmail" runat="server" Display="Dynamic"

     

     

    ControlToValidate="txtEmail" ErrorMessage="E-mail is required" Text="E-mail Required" ValidationGroup="accountHolderInfo" />

     

     

    <asp:RegularExpressionValidator ID="regEmail" runat="server" ControlToValidate="txtEmail" Display="Dynamic" ErrorMessage="Enter Valid Email"

     

     

    ValidationGroup="accountHolderInfo" ValidationExpression ="^[\w\.\-]+@[a-zA-Z0-9\-]+(\.[a-zA-Z0-9\-]{1,})*(\.[a-zA-Z]{2,3}){1,2}$"></asp:RegularExpressionValidator>

     

     

    <asp:Label ID="lblEmail" runat="server" Visible="false" ForeColor = "Red" ></asp:Label>

     

     

    </td>

     

     

    </tr>

     

     

    </table>

     

     

     

    </ItemTemplate>

     

     

    </telerik:RadPanelItem>

     

    could any one help me in this regard?

    Thanks,
    Bharath
  2. Paul
    Admin
    Paul avatar
    4281 posts

    Posted 07 Oct 2009 Link to this post

    Hi Bharathwajan Venkatanarayanan,

    You cannot access the label control on the client as it is not rendered on the page yet, because you have set its visibility to false:

    ... 
    ... 
    <asp:Label ID="lblEmail" runat="server" Visible="false" ForeColor="Red"></asp:Label> 
    ... 
    ... 

    Here's your modified code snippet that shows the needed approach.

    <form id="form1" runat="server"
        <telerik:RadScriptManager ID="RadScriptManager1" runat="server"
        </telerik:RadScriptManager> 
        <telerik:RadPanelBar ID="pnlbarRegn" runat="server"
            <Items> 
                <telerik:RadPanelItem runat="server" Text="Root RadPanelItem1"
                    <Items> 
                        <telerik:RadPanelItem Enabled="true" Text="Step 3: Account Holder Information" runat="server" 
                            Font-Underline="false" FocusedCssClass=""
                            <Items> 
                                <telerik:RadPanelItem runat="server" Value="AccountHolderInformation"
                                    <ItemTemplate> 
                                        <table width="100%" border="0" cellspacing="0" cellpadding="2"
                                            <tr> 
                                                <td align="right"
                                                    Email 
                                                </td> 
                                                <td align="left"
                                                    <telerik:RadTextBox ID="txtEmail" runat="server" Skin="" CssClass="text" MaxLength="255" 
                                                        AutoPostBack="false" onfocus="Text1_focus()"
                                                    </telerik:RadTextBox><asp:RequiredFieldValidator ID="rfvEmail" runat="server" Display="Dynamic" 
                                                        ControlToValidate="txtEmail" ErrorMessage="E-mail is required" Text="E-mail Required" 
                                                        ValidationGroup="accountHolderInfo" /> 
                                                    <asp:RegularExpressionValidator ID="regEmail" runat="server" ControlToValidate="txtEmail" 
                                                        Display="Dynamic" ErrorMessage="Enter Valid Email" ValidationGroup="accountHolderInfo" 
                                                        ValidationExpression="^[\w\.\-]+@[a-zA-Z0-9\-]+(\.[a-zA-Z0-9\-]{1,})*(\.[a-zA-Z]{2,3}){1,2}$"></asp:RegularExpressionValidator> 
                                                    <asp:Label ID="lblEmail" runat="server" Text="lbl" Style="display: none" ForeColor="Red"></asp:Label> 
                                                </td> 
                                            </tr> 
                                        </table> 
                                    </ItemTemplate> 
                                </telerik:RadPanelItem> 
                            </Items> 
                        </telerik:RadPanelItem> 
                    </Items> 
                </telerik:RadPanelItem> 
            </Items> 
        </telerik:RadPanelBar> 
        <telerik:RadScriptBlock runat="server" ID="RadScriptBlock1"
     
            <script type="text/javascript"
     
                function Text1_focus() { 
                    var lblEmail = $get('<%= ((Label)pnlbarRegn.FindItemByValue("AccountHolderInformation").FindControl("lblEmail")).ClientID %>'); 
                    alert(lblEmail); 
                }   
            </script> 
     
        </telerik:RadScriptBlock> 
        </form> 


    Regards,
    Paul
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
  3. UI for ASP.NET Ajax is Ready for VS 2017
Back to Top