Q: Am I crazy? I've got the event. The name's copy/pasted so I know it's no typo. What am I missing here? (Don't worry about parameters, please, this is for training and I've been told not to use them at this time)
<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-->
The codebehind:
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;
}
}
In trigger, you only need to specify event Name.
It should be
<asp:AsyncPostBackTrigger ControlID="BtnEpl" EventName="Click" />
instead
<asp:AsyncPostBackTrigger ControlID="BtnEpl" EventName="BtnEpl_Click" />
Are you closing the First ContentTemplate at some point? In case you do it after the Button Markup please enable ChildrenAsTriggers="true".
Just in the interest of giving this question an answer, I must point out my mistake. @Muhammad asked me why the panels were set to visible=false; this was because of the way I tried to approach the page structure. I wanted to use ajax to display input forms, and then hide them upon submission to the db and display the data in read-only format, so I thought I'd put both forms in update panels and make them invisible until they were called by the dropdownlist. Unfortunately what I discovered is that triggers won't fire on invisible controls. Don't quote me, but as I understand it, this is because invisible server side controls don't send markup to the browser. Lesson learned.