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);
}
}
我試圖在頁面上添加幾個按鈕,但他們沒有工作。 當我附加過程時,斷點會觸發其他事件,但不會觸發按鈕單擊。 任何有關我在這段代碼中犯了什麼錯誤的建議?
澄清:是否有任何錯誤發生,或者服務器是否忽略了點擊? –
沒有任何錯誤;點擊按鈕沒有任何事情發生。破發點根本沒有受到打擊。 –
您的母版頁中是否有表單runat =「server」? – rach