Мертвая кнопка на панели обновлений? - PullRequest
0 голосов
/ 02 мая 2011

Используя asp.net и C #, я создаю учебный проект для обучения, где я ЯВНО ЗАПРЕЩЕН использовать параметризацию. ОДНОЗНАЧНО. Моим боссом. Это мой первый проект, и он решил, что мне нужно сосредоточиться на других вещах. При этом у меня проблема в том, что у меня есть страница добавления продукта, на которой отображаются панели обновления с формами ввода, которые становятся видимыми при выборе в раскрывающемся списке. Это нормально работает. Однако кнопка отправки в форме продукта (которая должна сделать форму ввода пользователя невидимой, вставить данные в базу данных, отобразить другую панель обновления как видимую и заполнить метки теми же данными) не работает. Это ничего не делает. Мой исходный код и код ниже, соответственно. И снова, явно запрещено параметризоваться.

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

Ответы [ 2 ]

1 голос
/ 02 мая 2011

Я могу заявить об очевидном, но в предоставленном вами примере кода кнопка не имеет указанного обработчика события OnClick.

Кроме того, вам может понадобиться явно добавить синхронный триггер в UpdatePanel или указать ChildrenAsTriggers = "false" в UpdatePanel.

0 голосов
/ 02 мая 2011

На вашей кнопке установлено AutoPostBack="true"

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...