0
我目前正在使用帶有選項卡的網頁。我在此代碼中實現更新面板的目的是爲了防止當我按下任何按鈕時當前跳回第一個選項卡的選項卡。我在每個添加和保存的標籤中都有2個圖像按鈕。在實現更新面板後,添加按鈕正在工作,因爲它能夠向網格視圖添加新行並保留在同一個選項卡上,但保存按鈕不起作用,並且在單擊後沒有任何效果。我目前是ASP.NET C#的新手。希望從StackOverFlow獲得幫助以幫助我查看代碼並指出我的錯誤。感謝大家。ImageButton不能在Tab更新面板上工作
<html>
<head runat="server">
<title>ERO</title>
</head>
<body>
<div class="tab">
<button class="tabName" onclick="openTab(event, 'Student')" id="defaultOpen">Student</button>
<button class="tabName" onclick="openTab(event, 'Lecturer')">Lecturer</button>
<button class="tabName" onclick="openTab(event, 'Subject')">Subject</button>
</div>
<form id="form1" runat="server">
<h1>ERO</h1>
<div id="Student" class="tabContent">
<h1>Student Registration</h1>
<div>
<asp:GridView ID="StudentGridView" runat="server" AutoGenerateColumns="false" OnRowDataBound="OnRowDataBoundStudent" ShowFooter="true" OnRowDeleting="StudentGridView_RowDeleting">
<Columns>
<asp:BoundField DataField="RowNumber" HeaderText="#" />
<asp:TemplateField HeaderText="Student Name" ItemStyle-Width="100">
<ItemTemplate>
<asp:TextBox ID="StudentName" runat="server" Text='<%# Eval("StudentName") %>' />
<asp:RequiredFieldValidator ID="StudentNameValidator" runat="server" ControlToValidate="StudentName" ErrorMessage="*" ValidationGroup="StudentGroup" />
<asp:RegularExpressionValidator ID="StudentNameValidator1" runat="server" ControlToValidate="StudentName" ErrorMessage="Cannot contain '." ValidationGroup="StudentGroup" ValidationExpression="[^']*" />
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Student ID" ItemStyle-Width="100">
<ItemTemplate>
<asp:TextBox ID="StudentID" runat="server" Text='<%# Eval("StudentID") %>' />
<asp:RequiredFieldValidator ID="StudentIDValidator" runat="server" ControlToValidate="StudentID" ErrorMessage="*" ValidationGroup="StudentGroup" />
<asp:RegularExpressionValidator ID="StudentIDValidator1" runat="server" ControlToValidate="StudentID" ErrorMessage="Cannot contain '." ValidationGroup="StudentGroup" ValidationExpression="[^']*" />
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Student Address" ItemStyle-Width="200">
<ItemTemplate>
<asp:TextBox ID="StudentAddress" runat="server" Text='<%# Eval("StudentAddress") %>' Width="200" Height="50px" TextMode="MultiLine" />
<asp:RequiredFieldValidator ID="StudentAddressValidator" runat="server" ControlToValidate="StudentAddress" ErrorMessage="*" ValidationGroup="StudentGroup" />
<asp:RegularExpressionValidator ID="StudentAddressValidator1" runat="server" ControlToValidate="StudentAddress" ErrorMessage="Cannot contain '." ValidationGroup="StudentGroup" ValidationExpression="[^']*" />
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Student Phone Number" ItemStyle-Width="100">
<ItemTemplate>
<asp:TextBox ID="StudentPNumber" runat="server" Text='<%# Eval("StudentPNumber") %>' />
<asp:RequiredFieldValidator ID="StudentPNumberValidator" runat="server" ControlToValidate="StudentPNumber" ErrorMessage="*" ValidationGroup="StudentGroup" />
<asp:RegularExpressionValidator ID="StudentPNumberValidator1" runat="server" ControlToValidate="StudentPNumber" ErrorMessage="Cannot contain '." ValidationGroup="StudentGroup" ValidationExpression="[^']*" />
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Student Email Address" ItemStyle-Width="100">
<ItemTemplate>
<asp:TextBox ID="StudentEAddress" runat="server" Text='<%# Eval("StudentEAddress") %>' />
<asp:RequiredFieldValidator ID="StudentEAddressValidator" runat="server" ControlToValidate="StudentEAddress" ErrorMessage="*" ValidationGroup="StudentGroup" />
<asp:RegularExpressionValidator ID="StudentEAddressValidator1" runat="server" ControlToValidate="StudentEAddress" ErrorMessage="Cannot contain '." ValidationGroup="StudentGroup" ValidationExpression="[^']*" />
<asp:RegularExpressionValidator ID="StudentEAddressValidator2" runat="server" ControlToValidate="StudentEAddress" ErrorMessage="Email format incorrect." ValidationGroup="StudentGroup" ValidationExpression="\w+([-+.']\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*" />
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Student Course" ItemStyle-Width="200">
<ItemTemplate>
<asp:DropDownList ID="StudentCourse" runat="server" Width="200" />
<asp:RequiredFieldValidator ID="StudentCourseValidator" runat="server" ControlToValidate="StudentCourse" ErrorMessage="*" InitialValue="-- Select Course --" ValidationGroup="StudentGroup" />
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Student Password" ItemStyle-Width="100">
<ItemTemplate>
<asp:TextBox ID="StudentPassword" runat="server" Text='<%# Eval("StudentPassword") %>' />
<asp:RequiredFieldValidator ID="StudentPasswordValidator" runat="server" ControlToValidate="StudentPassword" ErrorMessage="*" ValidationGroup="StudentGroup" />
<asp:RegularExpressionValidator ID="StudentPasswordValidator1" runat="server" ControlToValidate="StudentPassword" ErrorMessage="Cannot contain '." ValidationGroup="StudentGroup" ValidationExpression="[^']*" />
</ItemTemplate>
</asp:TemplateField>
<asp:CommandField ShowDeleteButton="True" ValidationGroup="StudentGroup" />
</Columns>
</asp:GridView>
<asp:ImageButton ID="ButtonSaveNewStudent" runat="server" OnClick="ButtonSaveNewStudent_Click" ValidationGroup="StudentGroup" ImageUrl="Picture\Save.jpg" ImageAlign="Right" Width="50px" Height="50px" />
<asp:ImageButton ID="ButtonAddNewStudent" runat="server" OnClick="ButtonAddNewStudent_Click" ValidationGroup="StudentGroup" ImageUrl="Picture\Student_Add.jpg" ImageAlign="Right" Width="50px" Height="50px" />
</div>
</div>
<asp:ScriptManager ID="TabScriptManager" runat="server" />
<asp:UpdatePanel ID="LecturerUpdatePanel" UpdateMode="Conditional" runat="server">
<ContentTemplate>
<div id="Lecturer" class="tabContent">
<h1>Lecturer Registration
</h1>
<div>
<asp:GridView ID="LecturerGridView" runat="server" AutoGenerateColumns="false" OnRowDataBound="OnRowDataBoundLecturer" ShowFooter="true" OnRowDeleting="LecturerGridView_RowDeleting">
<Columns>
<asp:BoundField DataField="RowNumber" HeaderText="#" />
<asp:TemplateField HeaderText="Lecturer Name" ItemStyle-Width="100">
<ItemTemplate>
<asp:TextBox ID="LecturerName" runat="server" Text='<%# Eval("LecturerName") %>' />
<asp:RequiredFieldValidator ID="LecturerNameValidator" runat="server" ControlToValidate="LecturerName" ErrorMessage="*" ValidationGroup="LecturerGroup" />
<asp:RegularExpressionValidator ID="LecturerNameValidator1" runat="server" ControlToValidate="LecturerName" ErrorMessage="Cannot contain '." ValidationGroup="LecturerGroup" ValidationExpression="[^']*" />
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Lecturer ID" ItemStyle-Width="100">
<ItemTemplate>
<asp:TextBox ID="LecturerID" runat="server" Text='<%# Eval("LecturerID") %>' />
<asp:RequiredFieldValidator ID="LecturerIDValidator" runat="server" ControlToValidate="LecturerID" ErrorMessage="*" ValidationGroup="LecturerGroup" />
<asp:RegularExpressionValidator ID="LecturerIDValidator1" runat="server" ControlToValidate="LecturerID" ErrorMessage="Cannot contain '." ValidationGroup="LecturerGroup" ValidationExpression="[^']*" />
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Lecturer Address" ItemStyle-Width="200">
<ItemTemplate>
<asp:TextBox ID="LecturerAddress" runat="server" Text='<%# Eval("LecturerAddress") %>' Width="200" Height="50px" TextMode="MultiLine" />
<asp:RequiredFieldValidator ID="LecturerAddressValidator" runat="server" ControlToValidate="LecturerAddress" ErrorMessage="*" ValidationGroup="LecturerGroup" />
<asp:RegularExpressionValidator ID="LecturerAddressValidator1" runat="server" ControlToValidate="LecturerAddress" ErrorMessage="Cannot contain '." ValidationGroup="LecturerGroup" ValidationExpression="[^']*" />
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Lecturer Phone Number" ItemStyle-Width="100">
<ItemTemplate>
<asp:TextBox ID="LecturerPNumber" runat="server" Text='<%# Eval("LecturerPNumber") %>' />
<asp:RequiredFieldValidator ID="LecturerPNumberValidator" runat="server" ControlToValidate="LecturerPNumber" ErrorMessage="*" ValidationGroup="LecturerGroup" />
<asp:RegularExpressionValidator ID="LecturerPNumberValidator1" runat="server" ControlToValidate="LecturerPNumber" ErrorMessage="Cannot contain '." ValidationGroup="LecturerGroup" ValidationExpression="[^']*" />
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Lecturer Email Address" ItemStyle-Width="100">
<ItemTemplate>
<asp:TextBox ID="LecturerEAddress" runat="server" Text='<%# Eval("LecturerEAddress") %>' />
<asp:RequiredFieldValidator ID="LecturerEAddressValidator" runat="server" ControlToValidate="LecturerEAddress" ErrorMessage="*" ValidationGroup="LecturerGroup" />
<asp:RegularExpressionValidator ID="LecturerEAddressValidator1" runat="server" ControlToValidate="LecturerEAddress" ErrorMessage="Cannot contain '." ValidationGroup="LecturerGroup" ValidationExpression="[^']*" />
<asp:RegularExpressionValidator ID="LecturerEAddressValidator2" runat="server" ControlToValidate="LecturerEAddress" ErrorMessage="Email format incorrect." ValidationGroup="LecturerGroup" ValidationExpression="\w+([-+.']\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*" />
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Lecturer Course" ItemStyle-Width="200">
<ItemTemplate>
<asp:DropDownList ID="LecturerCourse" runat="server" Width="200" />
<asp:RequiredFieldValidator ID="LecturerCourseValidator" runat="server" ControlToValidate="LecturerCourse" ErrorMessage="*" InitialValue="-- Select Course --" ValidationGroup="LecturerGroup" />
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Lecturer Password" ItemStyle-Width="100">
<ItemTemplate>
<asp:TextBox ID="LecturerPassword" runat="server" Text='<%# Eval("LecturerPassword") %>' />
<asp:RequiredFieldValidator ID="LecturerPasswordValidator" runat="server" ControlToValidate="LecturerPassword" ErrorMessage="*" ValidationGroup="LecturerGroup" />
<asp:RegularExpressionValidator ID="LecturerPasswordValidator1" runat="server" ControlToValidate="LecturerPassword" ErrorMessage="Cannot contain '." ValidationGroup="LecturerGroup" ValidationExpression="[^']*" />
</ItemTemplate>
</asp:TemplateField>
<asp:CommandField ShowDeleteButton="True" ValidationGroup="LecturerGroup" />
</Columns>
</asp:GridView>
<asp:ImageButton ID="ButtonSaveNewLecturer" runat="server" OnClick="ButtonSaveNewLecturer_Click" ValidationGroup="LecturerGroup" ImageUrl="~/Picture/Save.jpg" ImageAlign="Right" Width="50px" Height="50px" />
<asp:ImageButton ID="ButtonAddNewLecturer" runat="server" OnClick="ButtonAddNewLecturer_Click" ValidationGroup="LecturerGroup" ImageUrl="~/Picture/Lecturer_Add.jpg" ImageAlign="Right" Width="50px" Height="50px" />
</div>
</div>
</ContentTemplate>
</asp:UpdatePanel>
<asp:UpdatePanel ID="SubjectUpdatePanel" UpdateMode="Conditional" runat="server">
<ContentTemplate>
<div id="Subject" class="tabContent">
<h1>Subject Registration</h1>
<div>
<asp:GridView ID="SubjectGridView" runat="server" AutoGenerateColumns="false" OnRowDataBound="OnRowDataBoundSubject" ShowFooter="true" OnRowDeleting="SubjectGridView_RowDeleting">
<Columns>
<asp:BoundField DataField="RowNumber" HeaderText="#" />
<asp:TemplateField HeaderText="Subject Name" ItemStyle-Width="120">
<ItemTemplate>
<asp:TextBox ID="SubjectName" runat="server" Text='<%# Eval("SubjectName") %>' />
<asp:RequiredFieldValidator ID="SubjectNameValidator" runat="server" ControlToValidate="SubjectName" ErrorMessage="*" ValidationGroup="SubjectGroup" />
<asp:RegularExpressionValidator ID="SubjectNameValidator1" runat="server" ControlToValidate="SubjectName" ErrorMessage="Cannot contain '." ValidationGroup="SubjectGroup" ValidationExpression="[^']*" />
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Subject ID" ItemStyle-Width="120">
<ItemTemplate>
<asp:TextBox ID="SubjectID" runat="server" Text='<%# Eval("SubjectID") %>' />
<asp:RequiredFieldValidator ID="SubjectIDValidator" runat="server" ControlToValidate="SubjectID" ErrorMessage="*" ValidationGroup="SubjectGroup" />
<asp:RegularExpressionValidator ID="SubjectIDValidator1" runat="server" ControlToValidate="SubjectID" ErrorMessage="Cannot contain '." ValidationGroup="SubjectGroup" ValidationExpression="[^']*" />
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Subject Credit Hour" ItemStyle-Width="120">
<ItemTemplate>
<asp:TextBox ID="SubjectCreditHour" runat="server" Text='<%# Eval("SubjectCreditHour") %>' />
<asp:RequiredFieldValidator ID="SubjectCreditHourValidator" runat="server" ControlToValidate="SubjectCreditHour" ErrorMessage="*" ValidationGroup="SubjectGroup" />
<asp:CompareValidator ID="SubjectCreditHourValidator1" runat="server" ControlToValidate="SubjectCreditHour" ErrorMessage="Must be number." Operator="DataTypeCheck" Type="Integer" ValidationGroup="SubjectGroup" />
<asp:RegularExpressionValidator ID="SubjectCreditHourValidator2" runat="server" ControlToValidate="SubjectCreditHour" ErrorMessage="Cannot contain '." ValidationGroup="SubjectGroup" ValidationExpression="[^']*" />
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Subject Course" ItemStyle-Width="500">
<ItemTemplate>
<asp:DropDownList ID="SubjectCourse" runat="server" Width="500" />
<asp:RequiredFieldValidator ID="SubjectCourseValidator" runat="server" ControlToValidate="SubjectCourse" ErrorMessage="*" InitialValue="-- Select Course --" ValidationGroup="SubjectGroup" />
</ItemTemplate>
</asp:TemplateField>
<asp:CommandField ShowDeleteButton="True" ValidationGroup="SubjectGroup" />
</Columns>
</asp:GridView>
<div align="center" style="width: 1960px">
<asp:ImageButton ID="ButtonAddNewSubject" runat="server" OnClick="ButtonAddNewSubject_Click" ValidationGroup="SubjectGroup" ImageUrl="Picture\Add.ico" Style="position: relative; top: 2px" Width="50px" Height="50px" />
<asp:ImageButton ID="ButtonSaveNewSubject" runat="server" OnClick="ButtonSaveNewSubject_Click" ValidationGroup="SubjectGroup" ImageUrl="Picture\Save.jpg" Style="position: relative; top: 2px" Width="50px" Height="50px" />
</div>
</div>
</div>
</ContentTemplate>
</asp:UpdatePanel>
<script>
function openTab(evt, Name) {
var i, tabName, tabContent;
tabName = document.getElementsByClassName("tabName");
for (i = 0; i < tabName.length; i++) {
tabName[i].className = tabName[i].className.replace("active", "");
}
tabContent = document.getElementsByClassName("tabContent");
for (i = 0; i < tabContent.length; i++) {
tabContent[i].style.display = "none";
}
document.getElementById(Name).style.display = "block";
evt.currentTarget.className += "active";
}
document.getElementById("defaultOpen").click();
</script>
</form>
</body>
</html>
嗨。 @ Asif.Ali謝謝你的回覆。刪除'UpdateMode ='Conditional''後,當我按下添加按鈕時,它將顯示來自其他選項卡的內容與當前選項卡中的內容,並且保存按鈕仍然無法工作。我也用' '嘗試了觸發模式,但它也不起作用。 –
所以嘗試手動觸發保存按鈕。 – AsifAli72090
嗨。 @ Asif.Ali感謝您的回覆。手動觸發與我之前評論中提到的相同嗎?如果相同,則不起作用。 –