zoukankan      html  css  js  c++  java
  • 禁用Viewstate在使用母版的内容页面里使用Datalist可能不触发事件的解决方案

    最近做一个网站,为了提高性能,所以在web.config里适用了如下代码:
     <pages enableEventValidation="false" validateRequest="false" theme="021friend" enableViewState="false" enableViewStateMac="false"/>
    有一个DataList控件,在它的模板里放置了两个按钮


    <asp:DataList ID="DataList1"  DataSourceID="SqlDataSource1" RepeatColumns=4 runat="server" DataKeyField="pic_id"  onitemcommand="DataList1_ItemCommand" width="162px"><ItemTemplate>
     
     
     


    <asp:Button CausesValidation="false"  runat=Server ID="delete" Text="删除照片" CommandName="delete"  BorderStyle=solid BorderColor=#336699 BorderWidth=1px/>
    <asp:Button  CausesValidation="false"  runat=Server ID="setup" Text="set" CommandName="setup"  BorderStyle=solid BorderColor=#336699 BorderWidth=1px/>

     
     
    </div>
     <hr />
    </ItemTemplate>
    </asp:DataList>

     DataList1的数据源在后台实现

    protected void Page_Load(object sender, EventArgs e)
        {
            if (!Page.IsPostBack)
            {
    ...
    DataList1.DataSource = ds.Tables[0];
           DataList1.DataBind();

            }
        }

    但是在执行过程中,通过设置断点,DataList1_ItemCommand根本不会执行,解决这个问题有2个方法:
    1)启用viewstate,但是这里在page指令里适用viewstate=true并不可以,因为你适用了母版,如果没有母版就可以的,所以你需要在web.config设置启用viewstate
    2)适用SqlDataSource控件,也就是在SqlDataSource里绑定DataLists
     




     
  • 相关阅读:
    微服务简介
    Apache httpd.conf
    搭建PHP开发环境
    搭建Apache开发环境
    Swift 项目编译优化(一)
    用Flutter 写一个简单页面
    Sign In With Apple(一)(转)
    Xcode DeviceSupport
    MQTT初始篇笔记整理
    UITableView使用过程中可能遇到的问题
  • 原文地址:https://www.cnblogs.com/mqingqing123/p/1012992.html
Copyright © 2011-2022 走看看