C# 页面按钮点击以后,有时能触发后台事件,有时不能触发后台事件.不触发事件的时候就只在本页面刷屏一次,一般是出什么问题了? 

解决方案 »

  1.   

    Page_Load里没有if(ispostback), 这时候经常会造成事件丢失之类的
      

  2.   

    我遇到过用VSS做修改时。要全部迁出后修改,不然也是偶然会出现这个情况。重写事件
      

  3.   

    <asp:datagrid id=DataGrid1 runat="server" DataSource="<%# OrderALL %>" CellPadding="3" Font-Name="Verdana" HeaderStyle-font-weight="fold" width="100%" Font-Names="Verdana" AllowSorting="True" BorderWidth="1px" BorderStyle="Solid" PageSize="15" Height="81px" AutoGenerateColumns="False" OnItemCommand="DataGrid1_ItemCommand" OnItemDataBound="DataGrid1_ItemDataBound" OnSortCommand="DataGrid1_SortCommand">
    <Columns>
    <asp:BoundColumn Visible="False" DataField="cbid" SortExpression="cbid" HeaderText="呈报编号"></asp:BoundColumn>
    <asp:HyperLinkColumn DataNavigateUrlField="cbid" DataNavigateUrlFormatString="javascript:var win =window.open('../ChengBao/prew_cb.aspx?cbid={0}','','toolbar=no,menubar=no,titlebar=yes,directories=no,resizable=yes,status=no,fullscreen=no,scrollbars=yes,top=100;left=100,width=800,height=600');" 
     DataTextField="cbid" SortExpression="cbid" HeaderText="呈报编号"></asp:HyperLinkColumn>
    <asp:BoundColumn DataField="被保险人" SortExpression="被保险人" HeaderText="被保险人"></asp:BoundColumn>
    <asp:BoundColumn DataField="保单号码" SortExpression="保单号码" HeaderText="保单号码"></asp:BoundColumn>
    <asp:BoundColumn DataField="赔案编号" SortExpression="赔案编号" HeaderText="报案号"></asp:BoundColumn>
    <asp:BoundColumn DataField="预估金额" SortExpression="预估金额" HeaderText="预估金额"></asp:BoundColumn>
    <asp:BoundColumn DataField="提交人名称" SortExpression="提交人名称" HeaderText="提交人"></asp:BoundColumn>
    <asp:BoundColumn DataField="提交日期" SortExpression="提交日期" HeaderText="提交日期"></asp:BoundColumn>
    <asp:BoundColumn DataField="当前位置名称" SortExpression="当前位置名称" HeaderText="当前位置"></asp:BoundColumn>
    <asp:BoundColumn DataField="核赔状态" SortExpression="核赔状态" HeaderText="状态"></asp:BoundColumn>
    <asp:BoundColumn Visible="False" DataField="呈报状态" SortExpression="呈报状态" HeaderText="呈报状态"></asp:BoundColumn>
    <asp:BoundColumn Visible="False" DataField="当前位置" SortExpression="当前位置" HeaderText="当前位置"></asp:BoundColumn>
    <asp:BoundColumn Visible="False" DataField="呈报位置" HeaderText="呈报位置"></asp:BoundColumn>
    <asp:BoundColumn Visible="False" DataField="二次状态" HeaderText="二次状态"></asp:BoundColumn>
    <asp:TemplateColumn>
    <ItemTemplate>
    <img src='../Images/<%# DataBinder.Eval(Container, "DataItem.打印").ToString() == "False" ? "spacer" : "bar_10" %>.gif'  />
    </ItemTemplate>
    </asp:TemplateColumn>
    <asp:TemplateColumn>
    <ItemTemplate>
    <asp:ImageButton id="Imagebutton1" runat="server" ImageUrl="../img/edit.gif" CommandName="editorder" 
     AlternateText="编辑"></asp:ImageButton>
    </ItemTemplate>
    </asp:TemplateColumn>
    </Columns>
    <PagerStyle Mode="NumericPages"></PagerStyle>
    </asp:datagrid>点击“编辑”按钮  触发DataGrid1_ItemCommand事件        protected void DataGrid1_ItemCommand(object source, System.Web.UI.WebControls.DataGridCommandEventArgs e)
            {
                if (e.CommandName == "editorder")
                {
                    if (this.CheckAuth("中级核赔呈报") >= 3)
                    {
                        System.Text.StringBuilder sql = new System.Text.StringBuilder();
                        sql.Append(" update 流程表 set empid='" + Session["EmpID"].ToString().Trim() + "' where cbid='" + e.Item.Cells[0].Text + "'");
                        DA.DbHelperSQL.ExecuteSql(sql.ToString());
                        Response.Redirect("edit_zje_hp.aspx?dqwz=" + e.Item.Cells[11].Text.ToString() + "&cbid=" + e.Item.Cells[0].Text + "&wz2=" + e.Item.Cells[13].Text);
                    }
                    else
                        JScript.Alert("您没有权限进行此操作!");            }
            }
      

  4.   

    1页面里面至少要有下面2个属性为true
    <%@ Page Language="C#" EnableViewState="True" AutoEventWireup="true" %>