繁体   English   中英

未找到按钮单击事件?

[英]Button click event not found?

问:我疯了吗? 我有活动。 这个名字是复制/粘贴的,所以我知道这不是错字。 我在这里想念什么? (请不要担心参数,这是用于训练的,我被告知此时不要使用它们)

      <asp:UpdatePanel ID="UdpEPL" runat="server" UpdateMode="Conditional" Visible="False">
            <Triggers>
                <asp:AsyncPostBackTrigger ControlID="BtnEpl" EventName="BtnEpl_Click" />
            </Triggers>
      <ContentTemplate> 

      <!--some label and textbox controls-->

      <br />
      <asp:Button ID="BtnEpl" runat="server" Text="Submit" AutoPostBack="True" 
                    onclick="BtnEpl_Click" />
      <br />

      <!--the second update panel-->

         <asp:UpdatePanel ID="UdpEplShow" runat="server" UpdateMode="Conditional" Visible="False">
                  <Triggers>
                           <asp:AsyncPostBackTrigger ControlID="BtnEpl" EventName="BtnEpl_Click" />
                  </Triggers>
         <ContentTemplate>      
      <!--more labels displaying the user input from the first update panel-->

代码隐藏:

 protected void BtnEpl_Click(object sender, EventArgs e)
        {
             string connectionString = System.Configuration.ConfigurationManager.ConnectionStrings["MyConnectionString"].ConnectionString;
            string EplQuery = "INSERT INTO EPL (Entity, Employees, CA, MI, NY, NJ, Primex, EplLim, EplSir, Premium, Wage, Sublim) VALUES ('" + TbEplEntity + "', '" + TbEplTotalEmpl + "', '" + TbEplCalEmpl + "', '" + TbEplMichEmpl + "', '" + TbEplNyEmpl + "', '" + TbEplNjEmpl + "', '" + TbEplPrimEx + "', '" + TbEplLim + "', '" + TbEplEplSir + "', '" + TbEplPrem + "', '" + TbEplWage + "', '" + TbEplInvestCost + "')";
            string EplIdQuery = "SELECT SCOPE_IDENTITY() AS LastInsertedInstanceId";

        using (SqlConnection EplConn = new SqlConnection(connectionString))
        {
            EplConn.Open();
            SqlCommand EplCmd = new SqlCommand(EplQuery, EplConn);
            SqlCommand EplIdCmd = new SqlCommand(EplIdQuery, EplConn);
            using (EplCmd)
            using (EplIdCmd)
            {
                EplCmd.ExecuteNonQuery();
                SqlDataReader EplDr = EplIdCmd.ExecuteReader();
                EplDr.Read();
                int lastInsertedInstanceId = Convert.ToInt32(EplDr[0]);


            }

            string x = Request.QueryString["InstanceId"];
            string EplShowQuery = "SELECT Entity, Employees, CA, MI, NY, NJ, Primex, EplLim, EplSir, Premium, Wage, Sublim FROM EPL WHERE InstanceId =" + x;
            using (SqlCommand EplShowCmd = new SqlCommand(EplShowQuery, EplConn))
            {
                SqlDataReader EplDr = EplShowCmd.ExecuteReader();
                EplDr.Read();
                LblEplShowEntity.Text = EplDr.GetString(0);
                LblEplShowTotalEmpl.Text = EplDr.GetInt32(1).ToString();
                LblEplShowCalEmpl.Text = EplDr.GetInt32(2).ToString();
                LblEplShowMichEmpl.Text = EplDr.GetInt32(3).ToString();
                LblEplShowNyEmpl.Text = EplDr.GetInt32(4).ToString();
                LblEplShowNjEmpl.Text = EplDr.GetInt32(5).ToString();
                LblEplShowPrimEx.Text = EplDr.GetInt32(6).ToString();
                LblEplShowLim.Text = EplDr.GetInt32(7).ToString();
                LblEplShowSir.Text = EplDr.GetInt32(8).ToString();
                LblEplShowPrem.Text = EplDr.GetInt32(9).ToString();
                LblEplShowWage.Text = EplDr.GetInt32(10).ToString();
                LblEplShowInvestCost.Text = EplDr.GetInt32(11).ToString();

            }
        }
            UdpEPL.Visible = false;
            UdpEplShow.Visible = true;


    }
}

在触发器中,您只需要指定事件名称。

它应该是

<asp:AsyncPostBackTrigger ControlID="BtnEpl" EventName="Click" />

反而

<asp:AsyncPostBackTrigger ControlID="BtnEpl" EventName="BtnEpl_Click" />

您是否在某个时候关闭了第一个 ContentTemplate? 如果您在按钮标记之后执行此操作,请启用 ChildrenAsTriggers="true"。

为了给这个问题一个答案,我必须指出我的错误。 @Muhammad 问我为什么将面板设置为 visible=false; 这是因为我尝试处理页面结构的方式。 我想使用 ajax 来显示输入 forms,然后在提交到数据库时隐藏它们并以只读格式显示数据,所以我想我会把 forms 都放在更新面板中并让它们不可见下拉列表。 不幸的是,我发现触发器不会在不可见的控件上触发。 不要引用我的话,但据我了解,这是因为不可见的服务器端控件不会将标记发送到浏览器。 学过的知识。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM