Why is ASP.NET ViewState saved using asp: dropdownlist but not asp: table?

Well, there is probably a very obvious answer to this question for many of you, but it puzzled me.

I have an asp.net web form and I have two controls on it (well, more than these two, but we will focus on them). The first is asp: dropdownlist and the second is asp: table .

Both of these controls are declared on the HTML side and populated (child controls added) on the code page.

My simple question (hopefully with a simple answer) is this:

Why is the viewport saved in the drop-down list and NOT for the table?

I need to populate a table every time the page loads, but I can populate the drop-down list once (using Not Page.IsPostBack), and it is saved.

NOTE. I read about the life cycle of ASP.NET pages, and I tried to place the same calls in events with the initials Init () and PreInit () with the same results.

What obvious detail will I skip here?

Thanks for the help.

+3
source share
3 answers

You have not missed anything, your assessment is correct. ASP.NET tables do not save their contents for viewing state.

I suggested that at least part of the reason is that the table can contain any amount of data of any type and in some cases can really add to the size of the view state.

, . , , , .

+3

asp:table ViewState, . , asp:panel ; , , .

+3

viewstate, , ... asp.net.

<asp:Table ID="Table1" runat="server">
    <asp:TableRow ID="TableRow1" runat="server">
        <asp:TableCell ID="TableCell1" runat="server">
        This is Cell 1
        </asp:TableCell>
        <asp:TableCell ID="TableCell2" runat="server">
        This is Cell 2
        </asp:TableCell>
    </asp:TableRow>
</asp:Table>

You can read more on how to do this at http://weblogs.asp.net/nannettethacker/archive/2008/01/24/html-tables-to-asp-net-table-controls.aspx .

You can also try adding runat="server"to the tag table.

Not answering your question directly, but thought it might be useful nonetheless.

0
source

Source: https://habr.com/ru/post/1784438/


All Articles