Cannot access controls in a RadPanelItem

11 posts, 1 answers
  1. Aron
    Aron avatar
    80 posts
    Member since:
    Dec 2005

    Posted 18 Nov 2010 Link to this post

    I have a RadPanelBar with RadPanelItem and it has some controls. I am trying to access a textbox in the RadPanelItem and I get errors like:

    Compiler Error Message: CS0103: The name 'ControlNameHere' does not exist in the current context

    page:
    http://beta.simpletick.com/marketplace/add/

    aspx:

    <telerik:RadPanelBar ID="RadPanelBar1" runat="server" Width="100%">
            <Items>
                 
                <telerik:RadPanelItem runat="server" Expanded="true" Text="Submit your theme now"
                    Width="100%" CssClass="PanelTitle">
                     
                   <ItemTemplate>
                                <table>
                                    <tr>
                                        <td>Theme Title:</td>
                                        <td>
                                            <asp:TextBox ID="ThemeTitle" runat="server"></asp:TextBox>
                                            <img src="../../img/icons/question.png" />
                                            <asp:RequiredFieldValidator ID="RequiredFieldValidator3" CssClass="required"  ControlToValidate="ThemeTitle" runat="server" ErrorMessage="Required" Display="Dynamic"></asp:RequiredFieldValidator>
                                            <asp:Label ID="ThemeTitleError" runat="server" />
                                             
                                        </td>
                                    </tr>
                                    <tr>
                                        <td>Zip File:</td>
                                        <td>
                                            <telerik:RadUpload ID="ZipFileRadUpload1" InitialFileInputsCount="1" ControlObjectsVisibility="None" MaxFileInputsCount="1" runat="server">
                                            </telerik:RadUpload>
                                            <img src="../../img/icons/question.png" />
                                            <asp:RequiredFieldValidator ID="RequiredFieldValidator2" CssClass="required" ControlToValidate="ZipFileRadUpload1" runat="server" ErrorMessage="Required" Display="Dynamic"></asp:RequiredFieldValidator>
                                            <asp:Label ID="ZipFileRadUpload1Error" runat="server" />
                                        </td>
                                    </tr>
                                    <tr>
                                        <td>Screenshot:</td>
                                        <td>
                                            <telerik:RadUpload ID="ScreenshotRadUpload1" InitialFileInputsCount="1" ControlObjectsVisibility="None" MaxFileInputsCount="1" runat="server">
                                            </telerik:RadUpload>
                                            <img src="../../img/icons/question.png" />
                                            <asp:RequiredFieldValidator ID="RequiredFieldValidator4" CssClass="required" ControlToValidate="ScreenshotRadUpload1" runat="server" ErrorMessage="Required" Display="Dynamic"></asp:RequiredFieldValidator>
                                            <asp:Label ID="ScreenshotRadUpload1Error" runat="server" />
                                        </td>
                                    </tr>
                                    <tr>
                                        <td>What Skin Matches Best?</td>
                                        <td>
                                            <telerik:RadComboBox ID="BestSkin" runat="server">
                                            <Items>
                                            <telerik:RadComboBoxItem Text="" Value="" />
                                            <telerik:RadComboBoxItem Text="" Value="" />
                                            <telerik:RadComboBoxItem Text="" Value="" />
                                            <telerik:RadComboBoxItem Text="" Value="" />
                                            <telerik:RadComboBoxItem Text="" Value="" />
                                            <telerik:RadComboBoxItem Text="" Value="" />
                                            <telerik:RadComboBoxItem Text="" Value="" />
                                            <telerik:RadComboBoxItem Text="" Value="" />
                                            <telerik:RadComboBoxItem Text="" Value="" />
                                            <telerik:RadComboBoxItem Text="" Value="" />
                                            <telerik:RadComboBoxItem Text="" Value="" />
                                            <telerik:RadComboBoxItem Text="" Value="" />
                                            </Items>
                                            </telerik:RadComboBox>
                                            <img src="../../img/icons/question.png" />
                                             
                                        </td>
                                    </tr>
                                    <tr>
                                        <td>How wide should event/product images be?</td>
                                        <td>
                                            <telerik:RadNumericTextBox ID="EventProductImageWidthSize" Value="250" ShowSpinButtons="true" MinValue="100" MaxValue="800" Type="Number" runat="server">
                                                <NumberFormat DecimalDigits="0" />
                                            </telerik:RadNumericTextBox>
                                        px
                                            <img src="../../img/icons/question.png" />
                                         
                                        </td>
                                    </tr>
                                    <tr>
                                        <td>Your PayPal Account:</td>
                                        <td>
                                            <asp:TextBox ID="PayPalAccount" MaxLength="50" runat="server"></asp:TextBox>
                                            <img src="../../img/icons/question.png" />
                                            <asp:RequiredFieldValidator ID="RequiredFieldValidator1" CssClass="required"  ControlToValidate="PayPalAccount" runat="server" ErrorMessage="Required" Display="Dynamic"></asp:RequiredFieldValidator>
                                            </td>
                                    </tr>
                                    <tr>
                                    <td>Selling Price:</td>
                                    <td>
                                        <telerik:RadNumericTextBox ID="SellingPrice" Value="25" ShowSpinButtons="true" MinValue="1" MaxValue="5000" Type="Currency" runat="server">
                                            </telerik:RadNumericTextBox>
                                         USD
                                            <img src="../../img/icons/question.png" />
                                    </td>
                                    </tr>
                                </table>
                                <br />
                                    <asp:Button ID="SubmitThemeButton"  runat="server"
            Text="Submit Theme"
            ToolTip="This will save your theme to the SimpleTick marketplace"
            onclick="SubmitThemeButton_Click" />
                                 
                            </ItemTemplate>
                </telerik:RadPanelItem>
                 
            </Items>
        </telerik:RadPanelBar>
  2. Answer
    Shinu
    Shinu avatar
    17764 posts
    Member since:
    Mar 2007

    Posted 19 Nov 2010 Link to this post

    Hello Aron,


    You need to get reference to the corresponding RadPanelItem and use the FindControl() method to get the control placed inside.

    Help documentation for accessing item: Accessing Items
    Help documentation for accessing control inside: Accessing Controls Inside Templates


    -Shinu.
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. Aron
    Aron avatar
    80 posts
    Member since:
    Dec 2005

    Posted 19 Nov 2010 Link to this post

    thanks! it works!
  5. Krishna
    Krishna avatar
    5 posts
    Member since:
    Feb 2014

    Posted 31 Mar 2014 Link to this post

    Can I get a sample code for accessing items in panel bar?
  6. Princy
    Princy avatar
    17421 posts
    Member since:
    Mar 2007

    Posted 31 Mar 2014 in reply to Krishna Link to this post

    Hi Krishna,

    Please have a look into the sample code snippet which works fine at my end.

    ASPX:
    <telerik:RadPanelBar ID="RadPanelBar1" runat="server">
        <Items>
            <telerik:RadPanelItem Text="Item1">
                <Items>
                    <telerik:RadPanelItem Text="Item1.1">
                    </telerik:RadPanelItem>
                </Items>
                <ItemTemplate>
                    <telerik:RadTextBox ID="RadTextBox1" runat="server" Text="Item Template">
                    </telerik:RadTextBox>
                </ItemTemplate>
            </telerik:RadPanelItem>
        </Items>
    </telerik:RadPanelBar>

    JavaScript:
    <script type="text/javascript">
        function pageLoad() {
            var panelbar = $find("<%=RadPanelBar1.ClientID %>");
            var item = panelbar.findItemByText("Item1");
            var TextBox = item.findControl("RadTextBox1");
        }
    </script>

    Thanks,
    Princy.
  7. Krishna
    Krishna avatar
    5 posts
    Member since:
    Feb 2014

    Posted 02 Apr 2014 in reply to Princy Link to this post

    Thanks Princy. However, I am trying to utilize the Required Field Validator for the text box. It does not pick up the text box control for validation.

      <td style="width: 83%; white-space: nowrap;">

                            <telerik:RadTextBox ID="txtboxid" runat="server" ClientInstanceName="txtinstance" TabIndex="1" Width="100%">
                                           </telerik:RadTextBox>
                                                                                                                                                
                            <asp:RequiredFieldValidator ID="ReqValidator" runat="server" Display="Dynamic"
                                              ControlToValidate="txtboxname" ErrorMessage="Required!" ToolTip=" Required!" Font-Bold="true" ForeColor="Maroon" Font-Size="Large" ValidationGroup="Save"></asp:RequiredFieldValidator>

        </td>
  8. Krishna
    Krishna avatar
    5 posts
    Member since:
    Feb 2014

    Posted 02 Apr 2014 Link to this post

    For some reason the java script code does not get executed until after all the code is executed. Hope I made some sense.
  9. Princy
    Princy avatar
    17421 posts
    Member since:
    Mar 2007

    Posted 03 Apr 2014 in reply to Krishna Link to this post

    Hi Krishna,

    I guess that you need RequiredFieldValidator for 'txtboxid'. From your code I have noticed that you are setting ControlToValidate property of RequiredFieldValidator to 'txtboxname' and your RadTextBox id is 'txtboxid'. Please try to change the ControlToValidate property of RequiredFieldValidator to 'txtboxid' which works as expected for me. 

    Hope this will helps you.
    Thanks,
    Princy.
  10. Krishna
    Krishna avatar
    5 posts
    Member since:
    Feb 2014

    Posted 03 Apr 2014 in reply to Princy Link to this post

    Hi Princy,

    It was a typo while sending you the pseudo code. All I want to know is where to write the head tag in the ASP content / master page, so that I can set a reference to my .js file.

    Currently, I am trying to place it in the source of the Master page but I receive the following error: Validation(XHTML5) content is not supported out of script or asp:content regions. Even If I place it inside content tag, it says, the element 'head' cannot be nested within 'div'.
  11. Princy
    Princy avatar
    17421 posts
    Member since:
    Mar 2007

    Posted 03 Apr 2014 in reply to Krishna Link to this post

    Hi Krishna,

    Please try to attach the JavaScript reference inside the <head> tag of MasterPage as follows.

    ASPX:
    <head runat="server">
        <script src="../JS/JScript.js" type="text/javascript"></script>
        <title></title>
        <asp:ContentPlaceHolder ID="head" runat="server">
        </asp:ContentPlaceHolder>
    </head>

    Thanks,
    Princy.
  12. Krishna
    Krishna avatar
    5 posts
    Member since:
    Feb 2014

    Posted 08 Apr 2014 Link to this post

    Hi Princy,

    This is what solved my problem for the required field validator. This is due to a general configuration issue between the new unobtrusive ASP.NET 4.5 validation and jQuery. The way to workaround this issue is to disable the Unobstrusive validation mode with the following line in the web.config. 

    <appSettings>
           ...
           ...

        <add key="ValidationSettings:UnobtrusiveValidationMode" value="None" />

    </appSettings>



    Thanks a lot for all your help!  

    Regards,
    Krishna














Back to Top
UI for ASP.NET Ajax is Ready for VS 2017