开发者

Dead button on update panel?

开发者 https://www.devze.com 2023-03-01 18:25 出处:网络
Using asp.net and C#, I\'m building a practice project for training, where I have been EXPRESSLY FORBIDDEN to use parameterization. EXPRESSLY. By my boss. This is my first project , and he decided I h

Using asp.net and C#, I'm building a practice project for training, where I have been EXPRESSLY FORBIDDEN to use parameterization. EXPRESSLY. By my boss. This is my first project , and he decided I had other things to focus on. That being said, my problem is that I've got an add product page that displays update panels with the input forms made visible upon selection in the dropdownlist. This functions fine. However, the submit button on the product form (which should make the user input form invisible, insert the data to the db, display another update panel as visible and populate the labels with that same data) is dead. It doesn't do anything. My source code and code behind are below, respectively. And again, EXPRESSLY forbidden to parameterize.

<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;
    }
}


I may be stating the obvious, but in the code sample you've provided the button doesn't have an OnClick event handler specified.

Short of that, you may have to explicitly add a synchronous Trigger in the UpdatePanel or specify ChildrenAsTriggers="false" in the UpdatePanel.


On your button set AutoPostBack="true"

0

精彩评论

暂无评论...
验证码 换一张
取 消