zoukankan      html  css  js  c++  java
  • 禁用ViewState后,WebForm还有意义吗?

    禁用ViewState后,WebForm还有意义吗?

    WebForm 是基于事件的开发模式,禁用ViewState 后,破坏了控件事件的完整性,那我们还会在Web.config里面禁用掉ViewState吗?这么做什么意义,会不会破坏我们WebForm的开发模式。

      

    下面是禁用掉ViewState 后,控件事件对应的情况。

    Repeater

    操作:ItemCommand(失效)

    数据:DataBinding(可用)

    行为:ItemCreated(可用) , ItemDataBound(可用)

    Button

    操作:Click (可用), Command(待验证)

    数据:DataBinding(可用)

    DropDownList

    操作:SelectedIndexChanged(可用),TextChanged(待验证)

    数据:DataBinding(可用),DataBound(可用)

    下面列举三类Asp.net 中最常用的三类应用

      

    视图型

    <asp:FormView ID="FormView1" runat="server">

    <ItemTemplate>...</ItemTemplate>

    </asp:FormView>

    FormView1.DataSource = SomeDataSource;
    FormView1.DataBind();

      

    列表型

    <asp:Repeater ID="Repeater1" runat="server" OnItemCommand="Repeater1_ItemCommand">

    <ItemTemplate>

    <asp:LinkButton ID="LinkButton1" runat="server" CommandName="delete" CommandArgument='<%# Eval("ID") %>'>删除</asp:LinkButton>

    </ItemTemplate>

    </asp:Repeater>

     
    protected void Repeater1_ItemCommand(object source, RepeaterCommandEventArgs e) { ... }

    表单型

    <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>

    <asp:Button ID="Button1" runat="server" Text="Button" onclick="Button1_Click" />

    protected void Button1_Click(object sender, EventArgs e) { ... }

    这三个例子中,是否启用ViewState对于视图型、表单型应用都没有问题,列表型应用在禁用ViewState后彻底失效,三个操作带来的优势倒是挺明显就是源代码清爽了不少,页面的加载速度也快不少。

    总结:Asp.net引入ViewState本来是一笔很宝贵的财富,但是如果使用不当,会照成整个页面加载速度明显下降,是否禁用ViewState还是看具体的应用场景。

  • 相关阅读:
    学习方式的反省
    我又辞职了!
    mysql完全备份,增量备份及恢复脚本
    marquee.js jQuery 多功能无缝滚动插件
    ul与li应用样式及其兼容性
    闲谈 JavaScript 之事件绑定(转载自万戈)
    JavaScript 中万变不离其宗的 this 应用场景
    ScrollUp – 超轻量的可定制的回到顶部 jQuery 插件
    jQuery之Tab切换代码改进
    jQuery Unveil – 另一款非常轻量的延迟加载插件
  • 原文地址:https://www.cnblogs.com/JavCof/p/webform_viewstate.html
Copyright © 2011-2022 走看看