aspx页面内,div里面的按钮事件不执行了,在〔Web 窗体设计器生成的代码〕中有:
this.tbn_Search.Click += new System.EventHandler(this.tbn_Search_Click);
这行代码;private void tbn_Search_Click(object sender, System.EventArgs e)
{}
内也有执行的内容,
可就是页面允许不执行按钮事件,高手指教。

解决方案 »

  1.   

    你这句在哪里执行的:
    this.tbn_Search.Click += new System.EventHandler(this.tbn_Search_Click);你是不是动态加载的控件。
      

  2.   

    try ->// .aspx
    <asp:Button OnClick = "tbn_Search_Click" ...// 并且
    // .aspx.cs private void tbn_Search_Click(object sender, System.EventArgs e)》》protected void tbn_Search_Click(object sender, System.EventArgs e)
      

  3.   

    this.tbn_Search.Click += new System.EventHandler(this.tbn_Search_Click);
    是在   Web 窗体设计器生成的代码   里面的,系统自动生成的
      

  4.   

    Jinglecat(晓风残月 >> 问题需简洁,错误要详细) 
    试过了,还是没反应
      

  5.   

    不会又像上次似的 HTML里form 套form了吧?
      

  6.   

    如果是 05 的话,手动写吧就像 Jinglecat(晓风残月 >> 问题需简洁,错误要详细) 的方法
      

  7.   

    加个断点看看走不走 要是不走断点 再重新双击一下按钮 看它对应的事件还是不是以前的那个
    实在不行 就换个Button
      

  8.   

    Form只有一层一起也出现过事件丢失,但是重新双击一下就会有的,这次怎么都不行,我新建一个页面html复制过去都不行,按钮删除,重新加一个也不行,vs2003的,
    这次郁闷大了
      

  9.   

    恩2003老是会出现过这种情况
    把button从div中拿出来看看
      

  10.   

    是不是你的页面用了验证控件,然后验证没通过就不能执行后台代码了PS:你点击了按钮后会不会执行page_load中的代码
      

  11.   

    this.tbn_Search.Click += new System.EventHandler(this.tbn_Search_Click);
    这行代码要放在init事件里面!!
      

  12.   

    啊,按钮在div外面可以执行的。
      

  13.   

    怎么办?在div外面可以执行,放到div里面就不行了,可他的位置就是要在div里面啊
      

  14.   

    你的 div 具有 runat=server ?
      

  15.   

    using System;
    using System.Collections;
    using System.ComponentModel;
    using System.Data;
    using System.Drawing;
    using System.Web;
    using System.Web.SessionState;
    using System.Web.UI;
    using System.Web.UI.WebControls;
    using System.Web.UI.HtmlControls;using NetGold.RunSP;
    using System.Configuration;
    using WebGold.Classes;
    namespace WebGold2
    {
    /// <summary>
    /// Simu_Buy 的摘要说明。
    /// </summary>
    public class Simu_Buy : System.Web.UI.Page
    {
    protected System.Web.UI.WebControls.Label lb_USDRate;
    protected System.Web.UI.WebControls.TextBox tb_Name;
    protected System.Web.UI.WebControls.DropDownList ddl_Sort;
    protected System.Web.UI.WebControls.DropDownList ddl_Year;
    protected System.Web.UI.WebControls.DropDownList ddl_Month;
    protected System.Web.UI.WebControls.DropDownList ddl_Day;
    protected System.Web.UI.WebControls.DataGrid pdg_BuyList;
    protected System.Web.UI.WebControls.Literal LtlPageIndex;
    protected System.Web.UI.WebControls.Literal LtlPageCount;
    protected System.Web.UI.WebControls.Literal LtlPageSize;
    protected System.Web.UI.WebControls.Literal LtlRecordCount;
    protected System.Web.UI.WebControls.HyperLink LBtnFirst;
    protected System.Web.UI.WebControls.HyperLink LBtnPrev;
    protected System.Web.UI.WebControls.HyperLink LBtnNext;
    protected System.Web.UI.WebControls.Button tbn_Search;
    protected System.Web.UI.HtmlControls.HtmlGenericControl content;
    protected System.Web.UI.WebControls.HyperLink LBtnLast;

    private void Page_Load(object sender, System.EventArgs e)
    {
    if(!IsPostBack)
    {
    try
    {
    if(Session["Name"]!=null)
    tb_Name.Text=Session["Name"].ToString();
    if(Session["Sort"]!=null)
    ddl_Sort.SelectedIndex=ddl_Sort.Items.IndexOf(ddl_Sort.Items.FindByValue(Session["Sort"].ToString()));
    if(Session["Year"]!=null)
    ddl_Year.SelectedIndex=ddl_Year.Items.IndexOf(ddl_Year.Items.FindByValue(Session["Year"].ToString()));
    else
    ddl_Year.SelectedIndex=ddl_Year.Items.IndexOf(ddl_Year.Items.FindByValue(System.DateTime.Now.Year.ToString()));
    if(Session["Month"]!=null)
    ddl_Month.SelectedIndex=ddl_Month.Items.IndexOf(ddl_Month.Items.FindByValue(Session["Month"].ToString()));
    else
    ddl_Month.SelectedIndex=ddl_Month.Items.IndexOf(ddl_Month.Items.FindByValue(System.DateTime.Now.Month.ToString()));
    if(Session["Day"]!=null)
    ddl_Day.SelectedIndex=ddl_Day.Items.IndexOf(ddl_Day.Items.FindByValue(Session["Day"].ToString()));
    else
    ddl_Day.SelectedIndex=ddl_Day.Items.IndexOf(ddl_Day.Items.FindByValue(System.DateTime.Now.Day.ToString()));
    DataSet ds=(new Newses()).GetParameter();
    if(ds.Tables[0].Rows.Count>0)
    lb_USDRate.Text=ds.Tables[0].Rows[0]["pUSDRate"].ToString();
    BuyListBind();
    }
    catch{}
    }
    } #region Web 窗体设计器生成的代码
    override protected void OnInit(EventArgs e)
    {
    //
    // CODEGEN: 该调用是 ASP.NET Web 窗体设计器所必需的。
    //
    InitializeComponent( );
    base.OnInit(e);
    }

    /// <summary>
    /// 设计器支持所需的方法 - 不要使用代码编辑器修改
    /// 此方法的内容。
    /// </summary>
    private void InitializeComponent()
    {    
    this.tbn_Search.Click += new System.EventHandler(this.tbn_Search_Click);
    this.Load += new System.EventHandler(this.Page_Load); }
    #endregion

    public void BuyListBind()
    {
    string sql="SELECT * FROM NetGoldSimulation.dbo.t_Buy WHERE 1=1";
    if(tb_Name.Text!="" && tb_Name.Text!="全部")
    {
    if(ddl_Sort.SelectedValue=="0")
    sql+=" and ugLoginName='"+tb_Name.Text+"'";
    if(ddl_Sort.SelectedValue=="1")
    sql+=" and bCode='"+tb_Name.Text+"'";
    }
    if(ddl_Year.SelectedValue!="0")
    sql+=" and Year(bTime)="+ddl_Year.SelectedValue;
    if(ddl_Month.SelectedValue!="0")
    sql+=" and Month(bTime)="+ddl_Month.SelectedValue;
    if(ddl_Day.SelectedValue!="0")
    sql+=" and Day(bTime)="+ddl_Day.SelectedValue;
    sql+=" order by bTime desc ";
    DataSet ds = (new Runpr()).RunSQL(sql);
    pdg_BuyList.DataSource=ds;
    pdg_BuyList.DataBind();
    pdg_BuyList.CurrentPageIndex = 0; string curpage;
    curpage=Request.QueryString["CurPage"]; if(curpage==""|| curpage==null || ds.Tables[0].Rows.Count==0)
    {
    LtlPageIndex.Text=(this.pdg_BuyList.CurrentPageIndex+1).ToString();
    }
    else
    {
    if(Convert.ToInt16(curpage)>=this.pdg_BuyList.PageCount)
    this.pdg_BuyList.CurrentPageIndex=pdg_BuyList.PageCount-1;
    else if(Convert.ToInt16(curpage)<0)
    this.pdg_BuyList.CurrentPageIndex=0;
    else
    this.pdg_BuyList.CurrentPageIndex=Convert.ToInt16(curpage);
    pdg_BuyList.DataBind();
    LtlPageIndex.Text=(this.pdg_BuyList.CurrentPageIndex+1).ToString();
    } LtlPageCount.Text=this.pdg_BuyList.PageCount.ToString();
    LtlPageSize.Text=this.pdg_BuyList.PageSize.ToString();
    LtlRecordCount.Text = ds.Tables[0].Rows.Count.ToString();
    LBtnFirst.NavigateUrl = "Simu_Buy.aspx?CurPage=0";
    LBtnPrev.NavigateUrl = "Simu_Buy.aspx?CurPage="+(this.pdg_BuyList.CurrentPageIndex-1).ToString();
    LBtnNext.NavigateUrl = "Simu_Buy.aspx?CurPage="+(this.pdg_BuyList.CurrentPageIndex+1).ToString();
    LBtnLast.NavigateUrl = "Simu_Buy.aspx?CurPage="+(this.pdg_BuyList.PageCount-1).ToString();
    ds.Dispose();
    } protected  void tbn_Search_Click(object sender, System.EventArgs e)
    {
    Session["Name"]=tb_Name.Text;
    Session["Sort"]=ddl_Sort.SelectedValue;
    Session["Year"]=ddl_Year.SelectedValue;
    Session["Month"]=ddl_Month.SelectedValue;
    Session["Day"]=ddl_Day.SelectedValue;
    BuyListBind();
    } private void pdg_BuyList_ItemDataBound(object sender, System.Web.UI.WebControls.DataGridItemEventArgs e)
    {//计算金额
    if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
    {
    double usdRate=Convert.ToDouble(lb_USDRate.Text);
    int num=100;
    if(e.Item.Cells[2].Text.ToUpper()=="AU10")
    num=10;
    double price=0;
    if(e.Item.Cells[3].Text!="")
    price=Convert.ToDouble(e.Item.Cells[3].Text);
    int quantity=0;
    if(e.Item.Cells[4].Text!="")
    quantity=Convert.ToInt32(e.Item.Cells[4].Text);
    double totle=usdRate*price*num*quantity;
    e.Item.Cells[5].Text=totle.ToString("F2");
    }
    } }
    }
      

  16.   

    <%@ Register TagPrefix="uc1" TagName="LeftSimulation" Src="LeftSimulation.ascx" %>
    <%@ Register TagPrefix="uc1" TagName="Top" Src="Top.ascx" %>
    <%@ Register TagPrefix="uc1" TagName="Bottom" Src="Bottom.ascx" %>
    <%@ Page language="c#" Codebehind="Simu_Buy.aspx.cs" AutoEventWireup="false" Inherits="WebGold2.Simu_Buy" %>
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html>
    <head>
    <title>中鼎黄金投资</title>
    <meta http-equiv="Content-Type" content="text/html; charset=gb2312">
    <meta content="" name="Keywords">
    <meta content="。" name="description">
    <link href="images/favicon.ico" type="image/x-icon" rel="icon">
    <link href="images/favicon.ico" type="image/x-icon" rel="shortcut icon">
    <link href="css/basic.css" type="text/css" rel="stylesheet">
    <link href="css/column.css" type="text/css" rel="stylesheet">
    <script language="JavaScript" src="js/common.js" type="text/javascript"></script>
    <style type="text/css">
    <!--
    .fe {
    width: 100%;
    font-family: Arial;
    /*color: #036;*/
    text-align: center;
    }
    .fe .th {
    height: 22px;
    color: #FFF;
    font-weight: normal;
    background: #1B4F93;
    }
    .fe td {
    border-bottom: #CCC dashed 1px;
    }
    -->
    </style>
    </head>
    <body MS_POSITIONING="GridLayout">
    <form id="Form1" method="post" runat="server">
    <uc1:top id="Top1" runat="server"></uc1:top>
    <div id="box">
    <div id="main">
    <div class="banner"><img src="images/b_simulation.jpg" width="630" height="120"></div>
    <div class="box_t_630 c"></div>
    <div class="border2_630 bg_c">
    <div id="nav"><a href="index.aspx">首页</A>&nbsp;&gt;&nbsp;<a href="Simu_Buy.aspx">买卖记录</A></div>
    <div id="content" runat=server>
    <asp:label id="lb_USDRate" runat="server" Visible="False">8.2</asp:label>
    <table height="50" border="0" cellPadding="0" cellSpacing="0">
    <tr>
    <td>&nbsp;
    <asp:TextBox id="tb_Name" runat="server" Width="80px"></asp:TextBox>&nbsp;
    <asp:dropdownlist id="ddl_Sort" runat="server">
    <asp:ListItem Value="0">按账号</asp:ListItem>
    <asp:ListItem Value="1">按代码</asp:ListItem>
    </asp:dropdownlist>&nbsp;日期
    <asp:DropDownList id="ddl_Year" runat="server">
    <asp:ListItem Value="0">不限</asp:ListItem>
    <asp:ListItem Value="2006">2006</asp:ListItem>
    <asp:ListItem Value="2007">2007</asp:ListItem>
    <asp:ListItem Value="2008">2008</asp:ListItem>
    <asp:ListItem Value="2009">2009</asp:ListItem>
    <asp:ListItem Value="2010">2010</asp:ListItem>
    </asp:DropDownList>年
    <asp:DropDownList id="ddl_Month" runat="server">
    <asp:ListItem Value="0">不限</asp:ListItem>
    <asp:ListItem Value="1">1</asp:ListItem>
    <asp:ListItem Value="2">2</asp:ListItem>
    <asp:ListItem Value="3">3</asp:ListItem>
    <asp:ListItem Value="4">4</asp:ListItem>
    <asp:ListItem Value="5">5</asp:ListItem>
    <asp:ListItem Value="6">6</asp:ListItem>
    <asp:ListItem Value="7">7</asp:ListItem>
    <asp:ListItem Value="8">8</asp:ListItem>
    <asp:ListItem Value="9">9</asp:ListItem>
    <asp:ListItem Value="10">10</asp:ListItem>
    <asp:ListItem Value="11">11</asp:ListItem>
    <asp:ListItem Value="12">12</asp:ListItem>
    </asp:DropDownList>月
    <asp:DropDownList id="ddl_Day" runat="server">
    <asp:ListItem Value="0">不限</asp:ListItem>
    <asp:ListItem Value="1">1</asp:ListItem>
    <asp:ListItem Value="2">2</asp:ListItem>
    <asp:ListItem Value="3">3</asp:ListItem>
    <asp:ListItem Value="4">4</asp:ListItem>
    <asp:ListItem Value="5">5</asp:ListItem>
    <asp:ListItem Value="6">6</asp:ListItem>
    <asp:ListItem Value="7">7</asp:ListItem>
    <asp:ListItem Value="8">8</asp:ListItem>
    <asp:ListItem Value="9">9</asp:ListItem>
    <asp:ListItem Value="10">10</asp:ListItem>
    <asp:ListItem Value="11">11</asp:ListItem>
    <asp:ListItem Value="12">12</asp:ListItem>
    <asp:ListItem Value="13">13</asp:ListItem>
    <asp:ListItem Value="14">14</asp:ListItem>
    <asp:ListItem Value="15">15</asp:ListItem>
    <asp:ListItem Value="16">16</asp:ListItem>
    <asp:ListItem Value="17">17</asp:ListItem>
    <asp:ListItem Value="18">18</asp:ListItem>
    <asp:ListItem Value="19">19</asp:ListItem>
    <asp:ListItem Value="20">20</asp:ListItem>
    <asp:ListItem Value="21">21</asp:ListItem>
    <asp:ListItem Value="22">22</asp:ListItem>
    <asp:ListItem Value="23">23</asp:ListItem>
    <asp:ListItem Value="24">24</asp:ListItem>
    <asp:ListItem Value="25">25</asp:ListItem>
    <asp:ListItem Value="26">26</asp:ListItem>
    <asp:ListItem Value="27">27</asp:ListItem>
    <asp:ListItem Value="28">28</asp:ListItem>
    <asp:ListItem Value="29">29</asp:ListItem>
    <asp:ListItem Value="30">30</asp:ListItem>
    <asp:ListItem Value="31">31</asp:ListItem>
    </asp:DropDownList>日&nbsp;&nbsp;
    <asp:button OnClick = "tbn_Search_Click" id="tbn_Search" runat="server" Text="查找"></asp:button></td>
    </tr>
       </table>
    <asp:DataGrid id="pdg_BuyList" runat="server" cellspacing="3" border="0" AutoGenerateColumns="False" AllowPaging="True" PageSize="20" class="fe">
    <HeaderStyle CssClass="th"></HeaderStyle>
    <Columns>
    <asp:BoundColumn Visible="False" DataField="bID" HeaderText="bID"></asp:BoundColumn>
    <asp:BoundColumn DataField="ugLoginName" HeaderText="账号"></asp:BoundColumn>
    <asp:BoundColumn DataField="bCode" HeaderText="代码"></asp:BoundColumn>
    <asp:BoundColumn DataField="bPrice" HeaderText="价格($)"></asp:BoundColumn>
    <asp:BoundColumn DataField="bQuantity" HeaderText="数量"></asp:BoundColumn>
    <asp:BoundColumn HeaderText="金额"></asp:BoundColumn>
    <asp:BoundColumn DataField="bType" HeaderText="类型"></asp:BoundColumn>
    <asp:BoundColumn DataField="bIncome" HeaderText="盈/亏"></asp:BoundColumn>
    <asp:BoundColumn DataField="bTime" HeaderText="时间"></asp:BoundColumn>
    </Columns>
    <PagerStyle Visible="False"></PagerStyle>
    </asp:DataGrid>
    <table width="100%" border="0" id="pages">
    <tr>
    <td>
    <asp:HyperLink id="LBtnFirst" runat="server">首页</asp:HyperLink>
    <asp:HyperLink id="LBtnPrev" runat="server">上一页</asp:HyperLink>
    <asp:HyperLink id="LBtnNext" runat="server">下一页</asp:HyperLink>
    <asp:HyperLink id="LBtnLast" runat="server">尾页</asp:HyperLink>
    第<asp:literal id="LtlPageIndex" runat="server"></asp:literal>页
    共<asp:literal id="LtlPageCount" runat="server"></asp:literal>页
    每页<asp:literal id="LtlPageSize" runat="server"></asp:literal>条
    共<asp:literal id="LtlRecordCount" runat="server"></asp:literal>条
    </td>
    </tr>
    </table>
    </div>
    </div>
    <div class="box_b_630 c"></div>
    </div>
    <uc1:LeftSimulation id="LeftSimulation1" runat="server"></uc1:LeftSimulation>
    </div>
    <uc1:bottom id="Bottom1" runat="server"></uc1:bottom>
    </form>
    </body>
    </html>
      

  17.   


    我觉得应该跟在div里面和外面没关系的
    败了!
      

  18.   

    重新注册.net组件即可。
    在Visual Studio  命令提示下运行 aspnet_regiis -i
      

  19.   

    我看了一下你的HTML代码 你的<DIV>和</DIV>是一样多的吗
    好象</div>多了几个吧?
      

  20.   

    我觉得以后能用table布局还是最好用table吧
    最好不用div
      

  21.   

    有些页面里的按钮事件是可以的,有些页面则不行我感觉是和div或者js有关,但我又找不到原因
      

  22.   

    可能还是程序其他地方问题,我copy后测试了可以的
      

  23.   

    去掉 <div id="content" runat=server>的 runat=server 看看
      

  24.   

    //这确实是个bug,可以这样解决
    if (Request.Params["__EVENTTARGET"] != null && Request.Params["__EVENTTARGET"].EndsWith("控件的ID") )
            {
     //           你执行事件的代码;
            }
      

  25.   

    解决方法:
    1.打上Framework1.1的sp1补丁

    2.将aspnet_client\system_web\1_1_4322\WebUIValidation.js中的
    function ValidatorCommonOnSubmit() {
        event.returnValue = !Page_BlockSubmit;
        Page_BlockSubmit = false;
    }
    改为
    function ValidatorCommonOnSubmit() {
        var result = !Page_BlockSubmit;
        Page_BlockSubmit = false;
        event.returnValue = result;
        return result;
    }
      

  26.   

    visual studio 2003 網頁開發里面就會存在這個問題,在aspx頁面中如果修改了部分代碼的話,對于頁面中所有的按鈕,超級鏈接,或則有提交服務器端事件的控件(如DropDownList)等,都需要在頁面中雙擊一次,如果那個沒有點擊的化,cs中的那個方法是不會執行的,像這種BUG還有例如:
    <a href="javascript:open_new(<%# DataBinder.Eval(Container.DataItem, "RECODE_NO") %>);" ><%# DataBinder.Eval(Container.DataItem, "RECODE_NO") %></a>
    這樣超級鏈接綁定,在編輯頁面的時候會出現無效綁定的提示錯誤,常常需要先注釋掉才能修改頁面
      

  27.   

    问题解决了,说来惭愧
    在top的用户控件里面居然有Form感谢各位的大力支持,感谢各位提供各种解决方法。
      

  28.   

    this.tbn_Search.Click += new System.EventHandler(this.tbn_Search_Click);删掉这句话,双击你那个按钮重做回传,这是vs2003的bug
      

  29.   

    vs2003 的BUG
    看来微软是不愿意 解决了.