RadAjaxPanel cannot access html table in C#

2 posts, 0 answers
  1. Jason
    Jason avatar
    20 posts
    Member since:
    Jun 2014

    Posted 12 Jun 2014 Link to this post

    I have a RadAjaxPanel that contains a table I am trying to update through the C# code. What happens is the user will first buy all the items, and click "Confirm Purchase". The original panel will go invisible, and then the final radajaxpanel will become visible. At that point, a method in C# will be called to populate the table inside with the final cart. However, in my C# code, when I try to add a newly created row to the table, I get an error that the table doesn't exist. Here's the code: <telerik:RadAjaxPanel ID="PanelCompletePurchase" runat="server" Visible="false">
        <h4>Complete Purchase</h4> 
        <table id="ReceiptTable">
            <tr>
               <th>Quantity</th>
               <th>Product</th>
               <th>Rate</th>
               <th>Price</th>
            </tr>
        </table>
        <asp:Label ID="Message" runat="server" ForeColor="Maroon"></asp:Label>
                    <br />
                    <asp:Label ID="Response" runat="server" ForeColor="maroon"></asp:Label>
                    <br />
                    <asp:Label ID="Debug" runat="server" forecolor="maroon"></asp:Label>
    </telerik:RadAjaxPanel>

    In my C# code, I doReceiptTable.Rows.Add(someCreatedRow);ReceiptTable is red and it shows unknown entity. How do I access the html table inside of the RadAjaxPanel? My Labels update just fine





  2. Princy
    Princy avatar
    17421 posts
    Member since:
    Mar 2007

    Posted 13 Jun 2014 in reply to Jason Link to this post

    Hi Jason,

    Please have a look into the sample code snippet which adds a row in the table on button click.

    ASPX:
    <telerik:RadAjaxPanel ID="PanelCompletePurchase" runat="server" Visible="true">
        <telerik:RadButton ID="Rad
    Button1"
    runat="server" Text="Add Row" OnClick="RadButton1_Click">
        </telerik:RadButton>
        <h4>
            Complete Purchase</h4>
        <table id="ReceiptTable" runat="server">
            <tr>
                <td>
                    Quantity
                </td>
                <td>
                    Product
                </td>
                <td>
                    Rate
                </td>
                <td>
                    Price
                </td>
            </tr>
        </table>
        <asp:Label ID="Message" runat="server" ForeColor="Maroon"></asp:Label>
        <br />
        <asp:Label ID="Response" runat="server" ForeColor="maroon"></asp:Label>
        <br />
        <asp:Label ID="Debug" runat="server" ForeColor="maroon"></asp:Label>
    </telerik:RadAjaxPanel>

    C#:
    protected void RadButton1_Click(object sender, EventArgs e)
    {
        HtmlTableRow tRow = new HtmlTableRow();
        HtmlTableCell cell1 = new HtmlTableCell();
        cell1.InnerText = "10";
        tRow.Cells.Add(cell1);
        HtmlTableCell cell2 = new HtmlTableCell();
        cell2.InnerText = "Pen";
        tRow.Cells.Add(cell2);
        HtmlTableCell cell3 = new HtmlTableCell();
        cell3.InnerText = "5";
        tRow.Cells.Add(cell3);
        HtmlTableCell cell4 = new HtmlTableCell();
        cell4.InnerText = "2";
        tRow.Cells.Add(cell4);
        ReceiptTable.Rows.Add(tRow);
    }

    Thanks,
    Princy.
Back to Top