2011-05-02 50 views
2

問: 我瘋了嗎?我有這個活動。該名稱的複製/粘貼,所以我知道這不是打字錯誤。我在這裏錯過了什麼? (不用擔心參數,請,這是訓練,我已經被告知不要在這個時候使用它們)未找到按鈕點擊事件?

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

代碼隱藏:

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; 


    } 
} 

回答

0

爲了給這個問題一個答案,我必須指出我的錯誤。 @穆罕默德問我爲什麼面板設置爲可見= false;這是因爲我試圖接近頁面結構的方式。我想用ajax來顯示輸入表單,然後在提交給數據庫時隱藏它們,並以只讀格式顯示數據,所以我想我會把這兩個表單放在更新面板中,並使它們不可見,直到它們被調用下拉列表。不幸的是,我發現觸發器不會觸發看不見的控件。不要引用我的意思,但據我瞭解,這是因爲無形的服務器端控件不會向瀏覽器發送標記。學過的知識。

4

在觸發器中,您只需指定事件名稱。

應該

<asp:AsyncPostBackTrigger ControlID="BtnEpl" EventName="Click" /> 

代替

<asp:AsyncPostBackTrigger ControlID="BtnEpl" EventName="BtnEpl_Click" /> 
+0

所以我不使用代碼隱藏(BtnEpl_Click)中的實際事件處理程序名稱?我應該只使用'點擊'? – 2011-05-02 05:51:11

+0

耶,我們只需要使用事件名稱而不是處理程序名稱。只是嘗試:) – 2011-05-02 05:52:08

+0

@Brazos:該屬性被稱爲** EventName **。 – 2011-05-02 05:53:00

0

你終場前的ContentTemplate在某些時候?如果您在按鈕標記後執行此操作,請啓用ChildrenAsTriggers =「true」。