[英]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>
<asp:TextBox ID="TbEplEntity" runat="server"></asp:TextBox>
<br />
<asp:Label ID="LblEplTotalEmpl" runat="server" Text="Total Number of Employees"></asp:Label>
<asp:TextBox ID="TbEplTotalEmpl" runat="server"></asp:TextBox>
<br />
<asp:Label ID="LblEplCalEmpl" runat="server" Text="Employees in California"></asp:Label>
<asp:TextBox ID="TbEplCalEmpl" runat="server"></asp:TextBox>
<br />
<asp:Label ID="LblEplMichEmpl" runat="server" Text="Employees in Michigan"></asp:Label>
<asp:TextBox ID="TbEplMichEmpl" runat="server"></asp:TextBox>
<br />
<asp:Label ID="LblEplNyEmpl" runat="server" Text="Employees in New York"></asp:Label>
<asp:TextBox ID="TbEplNyEmpl" runat="server"></asp:TextBox>
<br />
<asp:Label ID="LblEplNjEmpl" runat="server" Text="Employees in New Jersey"></asp:Label>
<asp:TextBox ID="TbEplNjEmpl" runat="server"></asp:TextBox>
<br />
<asp:Label ID="LblEplPrimEx" runat="server" Text="Primary/Excess"></asp:Label>
<asp:TextBox ID="TbEplPrimEx" runat="server"></asp:TextBox>
<br />
<asp:Label ID="LblEplLim" runat="server" Text="Limit"></asp:Label>
<asp:TextBox ID="TbEplLim" runat="server"></asp:TextBox>
<br />
<asp:Label ID="LblEplEplSir" runat="server" Text="EPL SIR"></asp:Label>
<asp:TextBox ID="TbEplEplSir" runat="server"></asp:TextBox>
<br />
<asp:Label ID="LblEplPrem" runat="server" Text="Premium"></asp:Label>
<asp:TextBox ID="TbEplPrem" runat="server"></asp:TextBox>
<br />
<asp:Label ID="LblEplWage" runat="server" Text="Wage & Hour Sublimit"></asp:Label>
<asp:TextBox ID="TbEplWage" runat="server"></asp:TextBox>
<br />
<asp:Label ID="LblEplInvestCost" runat="server" Text="Sublimit for Investigative Costs"></asp:Label>
<asp:TextBox ID="TbEplInvestCost" runat="server"></asp:TextBox>
<br />
<br />
<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>
<asp:Label ID="LblEplShowEntity" runat="server"></asp:Label>
<br />
<asp:Label ID="LblEplViewTotalEmpl" runat="server" Text="Total Number of Employees"></asp:Label>
<asp:Label ID="LblEplShowTotalEmpl" runat="server"></asp:Label>
<br />
<asp:Label ID="LblEplViewCalEmpl" runat="server" Text="Employees in California"></asp:Label>
<asp:Label ID="LblEplShowCalEmpl" runat="server"></asp:Label>
<br />
<asp:Label ID="LblEplViewMichEmpl" runat="server" Text="Employees in Michigan"></asp:Label>
<asp:Label ID="LblEplShowMichEmpl" runat="server"></asp:Label>
<br />
<asp:Label ID="LblEplViewNyEmpl" runat="server" Text="Employees in New York"></asp:Label>
<asp:Label ID="LblEplShowNyEmpl" runat="server"></asp:Label>
<br />
<asp:Label ID="LblEplViewNjEmpl" runat="server" Text="Employees in New Jersey"></asp:Label>
<asp:Label ID="LblEplShowNjEmpl" runat="server"></asp:Label>
<br />
<asp:Label ID="LblEplViewPrimEx" runat="server" Text="Primary/Excess"></asp:Label>
<asp:Label ID="LblEplShowPrimEx" runat="server"></asp:Label>
<br />
<asp:Label ID="LblEplViewLim" runat="server" Text="Limit"></asp:Label>
<asp:Label ID="LblEplShowLim" runat="server"></asp:Label>
<br />
<asp:Label ID="LblEplViewEplSir" runat="server" Text="EPL SIR"></asp:Label>
<asp:Label ID="LblEplShowSir" runat="server"></asp:Label>
<br />
<asp:Label ID="LblEplViewPrem" runat="server" Text="Premium"></asp:Label>
<asp:Label ID="LblEplShowPrem" runat="server"></asp:Label>
<br />
<asp:Label ID="LblEplViewWage" runat="server" Text="Wage & Hour Sublimit"></asp:Label>
<asp:Label ID="LblEplShowWage" runat="server"></asp:Label>
<br />
<asp:Label ID="LblEplViewInvestCost" runat="server" Text="Sublimit for Investigative Costs"></asp:Label>
<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.