繁体   English   中英

更新面板上的死按钮?

[英]Dead button on update panel?

使用 asp.net 和 C#,我正在构建一个用于训练的练习项目,我一直明确禁止使用参数化。 明确地。 通过我的老板。 这是我的第一个项目,他决定让我专注于其他事情。 话虽如此,我的问题是我有一个添加产品页面,该页面显示更新面板,其中输入 forms 在下拉列表中选择时可见。 这功能很好。 但是,产品表单上的提交按钮(应该使用户输入表单不可见,将数据插入数据库,将另一个更新面板显示为可见并使用相同数据填充标签)已失效。 它什么也没做。 我的源代码和后面的代码分别如下。 再次,明确禁止参数化。

<asp:UpdatePanel ID="UdpEPL" runat="server" UpdateMode="Conditional" Visible="False">
    <ContentTemplate>
        <asp:Label ID="LblEplEntity" runat="server" Text="Type Of Entity"></asp:Label>
&nbsp;&nbsp;&nbsp;
    <asp:TextBox ID="TbEplEntity" runat="server"></asp:TextBox>
    <br />
    <asp:Label ID="LblEplTotalEmpl" runat="server" Text="Total Number of Employees"></asp:Label>
&nbsp;&nbsp;&nbsp;
    <asp:TextBox ID="TbEplTotalEmpl" runat="server"></asp:TextBox>
    <br />
    <asp:Label ID="LblEplCalEmpl" runat="server" Text="Employees in California"></asp:Label>
&nbsp;&nbsp;&nbsp;
    <asp:TextBox ID="TbEplCalEmpl" runat="server"></asp:TextBox>
    <br />
    <asp:Label ID="LblEplMichEmpl" runat="server" Text="Employees in Michigan"></asp:Label>
&nbsp;&nbsp;&nbsp;
    <asp:TextBox ID="TbEplMichEmpl" runat="server"></asp:TextBox>
    <br />
    <asp:Label ID="LblEplNyEmpl" runat="server" Text="Employees in New York"></asp:Label>
&nbsp;&nbsp;&nbsp;
    <asp:TextBox ID="TbEplNyEmpl" runat="server"></asp:TextBox>
    <br />
    <asp:Label ID="LblEplNjEmpl" runat="server" Text="Employees in New Jersey"></asp:Label>
&nbsp;&nbsp;&nbsp;
    <asp:TextBox ID="TbEplNjEmpl" runat="server"></asp:TextBox>
    <br />
    <asp:Label ID="LblEplPrimEx" runat="server" Text="Primary/Excess"></asp:Label>
&nbsp;&nbsp;&nbsp;
    <asp:TextBox ID="TbEplPrimEx" runat="server"></asp:TextBox>
    <br />
    <asp:Label ID="LblEplLim" runat="server" Text="Limit"></asp:Label>
&nbsp;&nbsp;&nbsp;
    <asp:TextBox ID="TbEplLim" runat="server"></asp:TextBox>
    <br />
    <asp:Label ID="LblEplEplSir" runat="server" Text="EPL SIR"></asp:Label>
&nbsp;&nbsp;&nbsp;
    <asp:TextBox ID="TbEplEplSir" runat="server"></asp:TextBox>
    <br />
    <asp:Label ID="LblEplPrem" runat="server" Text="Premium"></asp:Label>
&nbsp;&nbsp;&nbsp;
    <asp:TextBox ID="TbEplPrem" runat="server"></asp:TextBox>
    <br />
    <asp:Label ID="LblEplWage" runat="server" Text="Wage &amp; Hour Sublimit"></asp:Label>
&nbsp;&nbsp;&nbsp;
    <asp:TextBox ID="TbEplWage" runat="server"></asp:TextBox>
    <br />
    <asp:Label ID="LblEplInvestCost" runat="server" Text="Sublimit for Investigative Costs"></asp:Label>
&nbsp;&nbsp;&nbsp;
    <asp:TextBox ID="TbEplInvestCost" runat="server"></asp:TextBox>

    <br />
    <br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
    <asp:Button ID="BtnEplSubmit" runat="server" Text="Submit" 
             />


    </ContentTemplate>
</asp:UpdatePanel>
<!--This is where the view only panel starts! Hope it works. -->
<asp:UpdatePanel ID="UdpEplShow" runat="server" UpdateMode="Conditional" Visible="False">
    <ContentTemplate>              
    <asp:Label ID="LblEplViewEntity" runat="server" Text="Type of Entity"></asp:Label>
&nbsp;&nbsp;&nbsp;
    <asp:Label ID="LblEplShowEntity" runat="server"></asp:Label>
    <br />
    <asp:Label ID="LblEplViewTotalEmpl" runat="server" Text="Total Number of Employees"></asp:Label>
&nbsp;&nbsp;&nbsp;
    <asp:Label ID="LblEplShowTotalEmpl" runat="server"></asp:Label>
    <br />
    <asp:Label ID="LblEplViewCalEmpl" runat="server" Text="Employees in California"></asp:Label>
&nbsp;&nbsp;&nbsp;
    <asp:Label ID="LblEplShowCalEmpl" runat="server"></asp:Label>
    <br />
    <asp:Label ID="LblEplViewMichEmpl" runat="server" Text="Employees in Michigan"></asp:Label>
&nbsp;&nbsp;&nbsp;
    <asp:Label ID="LblEplShowMichEmpl" runat="server"></asp:Label>
    <br />
    <asp:Label ID="LblEplViewNyEmpl" runat="server" Text="Employees in New York"></asp:Label>
&nbsp;&nbsp;&nbsp;
    <asp:Label ID="LblEplShowNyEmpl" runat="server"></asp:Label>
    <br />
    <asp:Label ID="LblEplViewNjEmpl" runat="server" Text="Employees in New Jersey"></asp:Label>
&nbsp;&nbsp;&nbsp;
    <asp:Label ID="LblEplShowNjEmpl" runat="server"></asp:Label>
    <br />
    <asp:Label ID="LblEplViewPrimEx" runat="server" Text="Primary/Excess"></asp:Label>
&nbsp;&nbsp;&nbsp;
    <asp:Label ID="LblEplShowPrimEx" runat="server"></asp:Label>
    <br />
    <asp:Label ID="LblEplViewLim" runat="server" Text="Limit"></asp:Label>
&nbsp;&nbsp;&nbsp;
    <asp:Label ID="LblEplShowLim" runat="server"></asp:Label>
    <br />
    <asp:Label ID="LblEplViewEplSir" runat="server" Text="EPL SIR"></asp:Label>
&nbsp;&nbsp;&nbsp;
    <asp:Label ID="LblEplShowSir" runat="server"></asp:Label>
    <br />
    <asp:Label ID="LblEplViewPrem" runat="server" Text="Premium"></asp:Label>
&nbsp;&nbsp;&nbsp;
    <asp:Label ID="LblEplShowPrem" runat="server"></asp:Label>
    <br />
    <asp:Label ID="LblEplViewWage" runat="server" Text="Wage &amp; Hour Sublimit"></asp:Label>
&nbsp;&nbsp;&nbsp;
    <asp:Label ID="LblEplShowWage" runat="server"></asp:Label>
    <br />
    <asp:Label ID="LblEplViewInvestCost" runat="server" Text="Sublimit for Investigative Costs"></asp:Label>
&nbsp;&nbsp;&nbsp;
    <asp:Label ID="LblEplShowInvestCost" runat="server"></asp:Label>


    </ContentTemplate>
</asp:UpdatePanel>


protected void BtnEplSubmit_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();

        }
    }
    if (TbEplInvestCost.Text != null)
    {

        //something about these next two lines seems unsafe, like they should be conditional, but I don't know why. Ask. 
        UdpEPL.Visible = false;
        UdpEplShow.Visible = true;
    }
}

我可能说的很明显,但是在您提供的代码示例中,按钮没有指定 OnClick 事件处理程序。

除此之外,您可能必须在 UpdatePanel 中显式添加同步触发器或在 UpdatePanel 中指定 ChildrenAsTriggers="false"。

在您的按钮上设置AutoPostBack="true"

暂无
暂无

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

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