2013-07-08 93 views
0

PFB以下代碼出現在我的.aspx文件之一中。我添加了一個按鈕,並在後面的代碼中添加了一個方法。我已將該過程附加到調試器,但按鈕單擊事件未被觸發。在我的應用程序的其餘部分的一切工作正常,但只有在這個屏幕上沒有事件在服務器端被觸發。如果我添加一個onClientClick事件,它會被解僱。服務器端的按鈕單擊事件未被觸發

<%@ Page Title="" Language="C#" MasterPageFile="~/Views/Site2.Master" AutoEventWireup="true" 
CodeBehind="AdminPage.aspx.cs" Inherits="RoomBook.Views.AdminPage" %> 

<asp:Content ID="Content1" ContentPlaceHolderID="head" runat="server"> 
<script language="javascript" type="text/javascript"> 
    $(function() { 
     var allPanels = $('.accordion > dd').hide(1000); 
     $('.accordion > dt > a').click(function() { 
      allPanels.slideUp(); 
      $(this).parent().next().show(1000); 
     }); 
     return false; 
    }); 

</script> 
</asp:Content> 
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" runat="server"> 
<asp:ScriptManager runat="server"> 
</asp:ScriptManager> 
<dl class="accordion"> 
    <dt><a href="#">Modify/Delete Room</a></dt> 
    <dd> 
     <asp:UpdatePanel runat="server"> 
      <ContentTemplate> 
       <label id="roomNumber0" class="itemLeft"> 
        Room Name 
       </label> 
       <asp:DropDownList class="inputTextRoom" ID="ddRoomName" runat="server"> 
       </asp:DropDownList> 
       <br /> 
       <label id="Label1" class="itemLeft"> 
        Status</label> 
       <asp:RadioButtonList class="radioButton" ID="rbStatus" runat="server"> 
        <asp:ListItem Text="Active"></asp:ListItem> 
        <asp:ListItem Text="Deactive"></asp:ListItem> 
       </asp:RadioButtonList> 
       <asp:Button ID="btnModify" runat="server" Text="Button" OnClick="btnModify_Click" /> 
      </ContentTemplate> 
     </asp:UpdatePanel> 
    </dd> 
</dl> 
</asp:Content> 

在方法定義後面的代碼是:

protected void btnModify_Click(object sender, EventArgs e) 
    { 

     RoomDomain roomdomain = new RoomDomain(); 
     string userName = (WindowsIdentity.GetCurrent().Name.ToString().Split('\\'))[1]; 

     if (!(ddRoomName.SelectedIndex == 0)) 
     { 
      roomdomain.RoomName = ddRoomName.SelectedItem.Value; 

      if (rbStatus.SelectedItem.Value == "Active") 
      { 
       roomdomain.IsActive = true; 
      } 
      else 
      { 
       roomdomain.IsActive = false; 
      } 
      adminPage.ModifyExistingRoom(roomdomain, userName); 
     } 

    } 

我試圖在頁面上添加幾個按鈕,但他們沒有工作。 當我附加過程時,斷點會觸發其他事件,但不會觸發按鈕單擊。 任何有關我在這段代碼中犯了什麼錯誤的建議?

+0

澄清:是否有任何錯誤發生,或者服務器是否忽略了點擊? –

+0

沒有任何錯誤;點擊按鈕沒有任何事情發生。破發點根本沒有受到打擊。 –

+0

您的母版頁中是否有表單runat =「server」? – rach

回答

0

您的按鈕位於更新面板中,因此您需要將該按鈕作爲觸發器添加到更新面板。添加到您的更新面板的底部:

</ContentTemplate> 
<Triggers> 
    <asp:AsyncPostBackTrigger ControlID="btnModify" /> 
</Triggers> 
</asp:UpdatePanel> 
+0

它仍然無法正常工作。在我的其他屏幕上,我以相同的方式使用了更新面板。 –

0

可以使用

<asp:AsyncPostBackTrigger ControlID="btnModify" /> 
+0

對不起,沒有工作。 –

+0

請添加屬性CauseValidation並在您的按鈕中將其設置爲false。 – Jack

0

我在2010年和2012創建新的Web窗體項目,無法生育的問題。我將您的腳本添加到頂級內容和標記中,並放入「MainContent」區域,在這兩種情況下,按鈕都沒有問題。 (我改變了代碼隱藏以簡單地切換單選按鈕,並且再次,在兩個項目中,它都工作正常。)我想知道如果你的腳本可以以某種方式導致問題。

+0

我創建了一個具有相同細節的新屏幕,工作正常,但我不知道爲什麼當我複製粘貼aspx內容時它不起作用。 –

0
<asp:Button ID="btnModify" runat="server" Text="Button" OnClick="btnModify_Click" UseSubmitBehavior="false"/> 

由於按鈕位於UpdatePanel內部,因此將其更改爲使用回發機制而不是您的瀏覽器表單提交。

Button.UseSubmitBehavior Property

相關問題