开发者

Which ASP.NET server control should I use?

开发者 https://www.devze.com 2023-01-30 22:34 出处:网络
I am looking for a simple lightweight ASP.NET server control to render 2 columns, a label and a radio button list. It literally should look like this.

I am looking for a simple lightweight ASP.NET server control to render 2 columns, a label and a radio button list. It literally should look like this.

Gender        Male/Female
Recommend us  Yes/No
and so on..

I feel that a repeater开发者_StackOverflow社区 or a datagrid is an overkill as this page needs to be high performant page and should be very light.

What server control do you recommend?


I feel that a repeater or a datagrid is an overkill as this page needs to be high performant page and should be very light.

i suggest pure html.


Smells like micro-optimization to me. Putting a repeater or datagrid on your page, for what you've specified above, will cause absolutely no delay in your page -- it's unnecessary, but it won't cause an issue. That is unless you're serving your site off a 2400 baud modem, which I doubt you are.

You haven't specified whether this control will be reused on multiple pages. If it won't be, you're just adding unnecessary complexity to your application by making it a web control. If all you're planning on doing is display static content like you have above, just keep it simple and display the fields just as you've displayed them above -- in a two column table, with a label in one, and radio buttons in the other.

If you are planning on reusing the control, my vote is to still add the controls as you would normally add a control -- without the use of a repeater or datagrid.


Please define high performance and "very light". If by "very light" you mean the rendered HTML markup, the Repeater control is the best choice because you control the markup completely. If you mean server-side processing, you probably want to write a custom control.

However, the gains over the repeater on the server-side would be negligible after the initial load if you can use output caching.


I tested a pure HTML solution vs a repeater solution with your example of two rows.
Control (blank page): 693 bytes rendered to client, .22 msec
Pure HTML solution: 1,029 bytes rendered to client, Server Processing time: .26 msec
Repeater solution: 2,196 bytes rendered to client, Server Processing time: .47 msec (the majority of the overhead is due to using a radiobuttonlist control)

You're talking about 1 kb uncompressed and .21 milliseconds overhead for using the repeater and radiobuttonlist.

In exchange, you get to maintain this:

<table>
    <tbody>
        <asp:Repeater ID="r" runat="server">
            <ItemTemplate>
                <tr>
                    <td>
                        <asp:Literal ID="l" runat="server" EnableViewState="false" Text='<%# Eval("Label") %>' />
                    </td>
                    <td>
                        <asp:RadioButtonList ID="rbl" runat="server" EnableViewState="false" 
                        DataSource='<%# ((Option)Container.DataItem).RadioButtonLabels %>'
                            RepeatDirection="Horizontal" RepeatLayout="Flow">
                        </asp:RadioButtonList>
                    </td>
                </tr>
            </ItemTemplate>
        </asp:Repeater>
    </tbody>
</table>

instead of this:

StringBuilder sb = new StringBuilder();

sb.Append("<table><tbody>");

foreach (Option option in options)
{
    sb.AppendFormat("<tr><td>{0}</td><td>", option.Label);

    foreach (string label in option.RadioButtonLabels)
    {
        sb.AppendFormat("{0}<input type=\"radio\" name=\"{1}\" value=\"{0}\" />", label, option.Label);
    }

    sb.Append("</td></tr>");
}

sb.Append("</tbody></table>");

Personally I prefer the 1st option, but you may prefer the second.


Sounds as a Web User Control would work out best for you as you will be able to keep the "over head" to a minimum.

Cheers, Stefan


I like the ListView for its flexibility.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号