2008-10-07 118 views
4

我有一個擁有單個UpdatePanel的UserControl的單個實例的頁面。 UpdatePanel內部有幾個Button控件。這些控件的Click事件在UserControl的Init事件中的代碼隱藏中被連接起來。在UpdatePanel中第一次部分回發後丟失Button.Click事件

我得到的第一個按鈕,我推,每次沒有問題的Click事件。之後,我只獲得一個按鈕的Click事件(SearchButton) - 其餘的都被忽略。我已經包含了下面的控件的代碼 - 爲簡潔起見,我已經排除了點擊事件處理方法,但他們都是標準的「無效Button_Click(對象發件人,EventArgs的)」的品種。有任何想法嗎?

<asp:UpdatePanel ID="PickerUpdatePanel" runat="server" UpdateMode="Conditional"> 
    <ContentTemplate> 
     <asp:Panel ID="Container" runat="server"> 
      <div> 
       <asp:TextBox ID="PickerResults" runat="server" style="margin-right: 3px;" SkinID="Plain" /> 
       <asp:Image 
        ID="LaunchPopup" runat="server" ImageUrl="~/images/icons/user_manage.png" 
        ImageAlign="Top" BorderColor="#294254" BorderStyle="Dotted" BorderWidth="1px" 
        Height="20px" Width="20px" style="cursor: pointer;" /> 
      </div> 
      <asp:Panel ID="PickerPanel" runat="server" DefaultButton="OKButton" CssClass="popupDialog" style="height: 227px; width: 400px; padding: 5px; display: none;"> 
       <asp:Panel runat="server" id="ContactPickerSearchParams" style="margin-bottom: 3px;" DefaultButton="SearchButton"> 
        Search: <asp:TextBox ID="SearchTerms" runat="server" style="margin-right: 3px;" Width="266px" SkinID="Plain" /> 
        <asp:Button ID="SearchButton" runat="server" Text="Go" Width="60px" SkinID="Plain" /> 
       </asp:Panel> 
       <asp:ListBox ID="SearchResults" runat="server" Height="150px" Width="100%" SelectionMode="Multiple" style="margin-bottom: 3px;" /> 
       <asp:Button ID="AddButton" runat="server" Text="Add >>" style="margin-right: 3px;" Width="60px" SkinID="Plain" /> 
       <asp:TextBox ID="ChosenPeople" runat="server" Width="325px" SkinID="Plain" /> 
       <div style="float: left;"> 
        <asp:Button ID="AddNewContact" runat="server" SkinID="Plain" Width="150px" Text="New Contact" /> 
       </div> 
       <div style="text-align: right;"> 
        <asp:Button ID="OKButton" runat="server" Text="Ok" SkinID="Plain" Width="100px" /> 
       </div> 
       <input id="SelectedContacts" runat="server" visible="false" /> 
      </asp:Panel> 
      <ajax:PopupControlExtender ID="PickerPopEx" runat="server" PopupControlID="PickerPanel" TargetControlID="LaunchPopup" Position="Bottom" /> 
     </asp:Panel> 
    </ContentTemplate> 
    <Triggers> 
     <asp:AsyncPostBackTrigger ControlID="AddButton" EventName="Click" /> 
     <asp:AsyncPostBackTrigger ControlID="SearchButton" EventName="Click" /> 
     <asp:AsyncPostBackTrigger ControlID="AddNewContact" EventName="Click" /> 
    </Triggers> 
</asp:UpdatePanel> 

public partial class ContactPicker : System.Web.UI.UserControl 
{ 
    protected void Page_Init(object sender, EventArgs e) 
    { 
     SearchButton.Click += new EventHandler(SearchButton_Click); 
     AddButton.Click += new EventHandler(AddButton_Click); 
     OKButton.Click += new EventHandler(OKButton_Click); 
    } 

    // Other code left out 
} 

回答

4

似乎在按鈕定義中添加UseSubmitBehavior =「false」已解決我的問題。仍然不知道爲什麼第一個按鈕點擊工作。

1

最可能的原因將是淨生成的控制改變客戶端ID。這些是動態分配的,可以在回發/部分回發之間進行更改。

如果控件被添加到面板動態,您的按鈕的ID可能是回發之間的不同造成的.Net是無法click事件綁定到正確的事件處理程序代碼。

+0

這是我的情況。如果您設置動態添加控件的ID,以確保它們是相同的每一次,它固定它 – 2013-09-18 15:24:16

0

在我的情況下,我在dgPatients_ItemDataBound事件處理程序中使用PostBackUrl屬性的LinkButton

那一刻我改變了LinkButtonHyperLink,問題消失。

相關問題