Unable to access controls in code behind when i use in RadPanel Bar

3 posts, 1 answers
  1. Sankar
    Sankar avatar
    6 posts
    Member since:
    Oct 2012

    Posted 22 Mar 2011 Link to this post


    <asp:UpdatePanel runat="server" ID="upZipCodes" UpdateMode="Conditional">
            <ContentTemplate>
                <br />
                <br />
                <telerik:RadAjaxPanel ID="GeoTarget" runat="server">
                    <telerik:RadPanelBar runat="server" ID="trpbGeoTarget" ExpandMode="SingleExpandedItem">
                        <Items>
                            <telerik:RadPanelItem Expanded="True" Text="Discreate ZipCodes List" runat="server"
                                Selected="true">
                                <Items>
                                    <telerik:RadPanelItem Value="DiscreateZipCodes" runat="server" Expanded="true">
                                      <ItemTemplate>
                                        
                                       <div class="text" style="background-color: #edf9fe">
                                      <asp:Panel runat="server" ID="pnlDiscrete">
                                            <table border="1" style="width: 790px; height: 476px;">
                <tr>
                    <td class="style17">
                        <asp:Label ID="Label4" runat="server" SkinID="InputRegular">Discrete List:</asp:Label>
                    </td>
                </tr>
                <tr>
                    <td class="style26">
                        <asp:Button ID="btnAddAll" runat="server" OnClick="btnAddAll_Click" Style="z-index: 1;
                            left: 83px; top: 2px; position: relative; width: 105px; height: 26px;" Text=" Add ZipCodes "
                            ToolTip="Click here to Add zipcode in List" />
                              <asp:Button ID="btnClearList" runat="server"
                            OnClick="btnClearList_Click" Style="z-index: 1; top: 3px; position: relative;
                            width: 74px; left: 175px" Text="Clear List" ToolTip="It Removes all ZipCode from List" />
                                 
                    </td>
                </tr>
                <tr>
                    <td align="left">
                        <asp:TextBox ID="txtZipCode" runat="server" Height="47px" SkinID="Long" TextMode="MultiLine"
                            ToolTip="Enter ZipCodes" Width="454px"></asp:TextBox>
                        <uc2:Helper ID="Helper3" runat="server" ResourceKey="ZipCode" />
                        <ajaxToolkit:FilteredTextBoxExtender ID="Validatior" runat="server" FilterType="Custom, Numbers"
                            TargetControlID="txtZipCode" ValidChars="," />
                        <asp:RequiredFieldValidator ID="rfvZip" runat="server" ControlToValidate="txtZipCode"
                            Display="Dynamic" ErrorMessage="* Enter Comma Sepertaed ZipCodes" SetFocusOnError="true"
                            SkinID="ClientMessaging"></asp:RequiredFieldValidator>
                    </td>
                </tr>
                <tr>
                    <td align="left">
                        <asp:Panel ID="pnlGeoTargetProfile" runat="server" ScrollBars="Both">
                            <asp:GridView ID="grdZipDiscreateList" runat="server" AutoGenerateColumns="False"
                                DataKeyNames="ZipCode" EnableModelValidation="True" RowStyle-Height="1px" ShowFooter="True"
                                SkinID="view" Width="779px" AllowPaging="True" overflow="auto" ScrollBars="Both">
                                <Columns>
                                    <asp:BoundField DataField="ZIPCode" HeaderText="ZipCode" ReadOnly="true" />
                                    <asp:BoundField DataField="City" HeaderText=" City Name" ReadOnly="true" />
                                    <asp:BoundField DataField="State" HeaderText="State" ReadOnly="true" />
                                    <asp:TemplateField HeaderText="Action" ItemStyle-HorizontalAlign="Center">
                                        <ItemTemplate>
                                            <asp:Panel ID="pnlDelete" runat="server">
                                                <asp:LinkButton ID="lnkRemove" runat="server" CommandArgument='<%# DataBinder.Eval(Container.DataItem, "ZIPCode") + "," + DataBinder.Eval(Container, "RowIndex") %>'
                                                    OnClientClick="return confirm('Are you remove want to remove this ZipCode from the Discrete list ? Do you wish to continue.');"
                                                    Text="Remove"><img alt="" src="../Images/Icons/remove.png" border="0" title="remove"></asp:LinkButton>
                                            </asp:Panel>
                                        </ItemTemplate>
                                        <ItemStyle HorizontalAlign="Center" />
                                    </asp:TemplateField>
                                </Columns>
                                <RowStyle Height=".5px" />
                            </asp:GridView>
                        </asp:Panel>
                    </td>
                </tr>
                <tr>
                    <td>
                         <asp:Button ID="btnSave" runat="server" SkinID="btnSave" Text=" Updates ZipCodes "
                            ToolTip="Click here to Update zipcodes in List" ValidationGroup="ClientDegree"
                            Width="157px" />
                        <asp:Button ID="btnCleargrid" runat="server" OnClick="btnCleargrid_Click" Style="z-index: 1;
                            left: 140px; top: 0px; position: relative; width: 133px; height: 26px" Text="Delete All ZipCodes"
                            ToolTip="It Removes all ZipCode from List" />
                        <asp:Button ID="btnClose" runat="server" OnClick="btnClose_Click" Style="z-index: 1;
                            left: 186px; top: 0px; position: relative; width: 52px; height: 26px" Text="Close" />
                                           
                    </td>
                </tr>
            </table>
             
        </asp:Panel>
                                        </div>
                                            <ul class="formList" id="accountInfo">
                                      </ItemTemplate>
                                     </telerik:RadPanelItem>
                                </Items>
                            </telerik:RadPanelItem>
                            <telerik:RadPanelItem Expanded="True" Text="States List" runat="server" Selected="true">
                                <Items>
                                    <telerik:RadPanelItem Value="States List" runat="server">
                                        <ItemTemplate>
                                            <div class="text" style="background-color: #edf9fe">
                                            </div>
                                            <ul class="formList" id="accountInfo">
                                                <asp:Panel runat="server" ID="pnlStateList">
                                                    <table border="1">
                                                        <tr>
                                                            <td class="style15">
                                                                <uc1:campus ID="campus" runat="server" />
                                                            </td>
                                                        </tr>
                                                    </table>
                                                </asp:Panel>
                                        </ItemTemplate>
                                    </telerik:RadPanelItem>
                                </Items>
                            </telerik:RadPanelItem>
                            <telerik:RadPanelItem Expanded="True" Text="ZipCodes Within Radius" runat="server"
                                Selected="true">
                                <Items>
                                    <telerik:RadPanelItem Value="ZipCodes in Radius" runat="server">
                                        <ItemTemplate>
                                            <ul class="formList" id="accountInfo">
                                                <asp:Panel ID="pnlMiles" runat="server">
                                                    <table border="1">
                                                        <tr>
                                                            <td class="style25">
                                                                <asp:Label ID="lblZipCodes" runat="server" Text="ZipCodes within: "></asp:Label>
                                                                <asp:TextBox ID="txtMiles" runat="server" Width="32px"></asp:TextBox><asp:RequiredFieldValidator
                                                                    ControlToValidate="txtMiles" ID="RequiredFieldValidator3" runat="server" Display="Dynamic"
                                                                    ErrorMessage="* Enter Miles" SetFocusOnError="true" SkinID="ClientMessaging"
                                                                    ValidationGroup="ClientDegree"></asp:RequiredFieldValidator>
                                                                <asp:Label ID="lblMilesOfRadious" runat="server" Text="Miles Of Radius: "></asp:Label>
                                                                <asp:TextBox ID="txtZipInMiles" runat="server" Width="90px"></asp:TextBox>
                                                                <uc2:Helper ID="Helper4" runat="server" ResourceKey="ZipCode" />
                                                                <asp:RequiredFieldValidator ControlToValidate="txtZipInMiles" ID="RequiredFieldValidator4"
                                                                    runat="server" Display="Dynamic" ErrorMessage="* Enter Numric ZipCodes" SetFocusOnError="true"
                                                                    SkinID="ClientMessaging" ValidationGroup="ClientDegree"></asp:RequiredFieldValidator>
                                                                <ajaxToolkit:FilteredTextBoxExtender ID="FilteredTextBoxExtender1" runat="server"
                                                                    FilterType="Custom, Numbers" TargetControlID="txtZipInMiles" ValidChars="," />
                                                            </td>
                                                        </tr>
                                                    </table>
                                                </asp:Panel>
                                        </ItemTemplate>
                                    </telerik:RadPanelItem>
                                </Items>
                            </telerik:RadPanelItem>
                        </Items>
                        <CollapseAnimation Duration="100" Type="None" />
                        <ExpandAnimation Duration="100" Type="None" />
                    </telerik:RadPanelBar>
                </telerik:RadAjaxPanel>
                <%--  <Items>
                    <telerik:RadPanelItem Text="Discrete List Of ZipCodes" Expanded="True">
                        <Items>
                            <telerik:RadPanelItem Text="Personal Folders" />
                             
                        </Items>--%>
                <br />
                <br />
            </ContentTemplate>
        </asp:UpdatePanel>
    I am unable to access my controls in my code behind and when i am trying to access my Controls i am getting an  error of "Controls are not existing in current context".
    I have attached my error file. I have very basic understanding of rad panal Bar. So can you please explin me in detail what the ploblem is.?
    Thanks in advance.
  2. Answer
    Shinu
    Shinu avatar
    17764 posts
    Member since:
    Mar 2007

    Posted 23 Mar 2011 Link to this post

    Hello Ramon,

    You can try the following code snippet to locates the TextBox in the  Button_click event handler.
    C#:
    protected void btnAddAll_Click(object sender, EventArgs e)
     {
         Button btn = sender as Button;
         TextBox txtbx = btn.Parent.FindControl("txtZipCode") as TextBox;
         txtbx.Text = "hai";
     }

    The following documentation shows more information on this.
    Accessing Controls Inside Templates

    Thanks,
    Shinu.
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. Sankar
    Sankar avatar
    6 posts
    Member since:
    Oct 2012

    Posted 23 Mar 2011 Link to this post

    thanks, it works.
Back to Top