asp.net - 在 Modalpopupextender 内的 Datalist 按钮中未触发
问题描述
我有一个数据列表,其中有一个打开 Modalpopupextender 的按钮。此 modalpopupextender 中有一个未触发的提交按钮。请指教。
<table style="width: 100%">
<tr>
<td colspan="2">
<asp:DataList ID="dl1" runat="server" CellPadding="20" RepeatDirection="Vertical"
Style="width: 100%;" OnItemCommand="dl1_ItemCommand" OnSelectedIndexChanged="dl1_SelectedIndexChanged">
<ItemTemplate>
<table style="background-color: White; padding: 10px; border-color: Gray; width: 100%;">
<tr>
<td style="width: 30%; text-align: center;">
<asp:Image ID="imgPhoto" runat="server" ImageUrl='
<%# "~/CoachPhoto/" + Eval("CoachId") + ".jpg" %>' Style="margin-right: 20px; margin-left: 50px;"
Height="150px" Width="150px" BorderColor="Black" BorderStyle="Solid" />
</td>
<td style="width: 40%;">
<table style="width: 100%;">
<tr>
<td>
<asp:Label ID="lblName" runat="server" Font-Size="Large" ForeColor="DarkBlue" Text='<%# String.Format("{0} {1} {2} {3}", Eval("FirstName"), Eval("LastName"), ", ", Eval("AcademyName")) %>'>
</asp:Label>
</td>
</tr>
<tr>
<td>
<asp:Label ID="lblLocation" Font-Size="Large" ForeColor="DarkBlue" runat="server"
Text='<%# Eval("Location") + ", " + Eval("City") %>'>
</asp:Label>
</td>
</tr>
<%--<tr>
<td>
<asp:Label ID="lblReview" ForeColor="Black" runat="server" Text="Review">
</asp:Label>
</td>
</tr>--%>
<tr>
<td>
<table style="width: 100%;">
<tr>
<td style="width: 50%;">
<div style="font-size: small;">
Sport
</div>
</td>
<td>
<div style="font-size: small;">
Starting at</div>
</td>
</tr>
<tr>
<td>
<asp:Label ID="lblSport" runat="server" Font-Size="Medium" ForeColor="Black" Text='<%# Eval("Sport") %>'>
</asp:Label>
</td>
<td>
<asp:Label ID="lblFees" runat="server" Font-Size="Medium" ForeColor="Black" Text='<%# String.Format("{0} {1} {2} {3}", "Rs", Eval("Fees"), "per", Eval("FeesType")) %>'>
</asp:Label>
</td>
</tr>
</table>
</td>
</tr>
<tr>
<td>
<table style="width: 100%;">
<tr>
<td style="width: 50%;">
<div style="font-size: small;">
Contact Number
</div>
</td>
<td>
<div style="font-size: small;">
Location</div>
</td>
</tr>
<tr>
<td>
<asp:HyperLink ID="hypTelephoneNumber" runat="server" NavigateUrl='<%# "tel:" + Eval("Mobile")%>'
Font-Size="Medium" ForeColor="Black" Text='<%# Eval("Mobile") %>' />
</td>
<td>
<asp:Label ID="lblCompleteLocation" runat="server" Font-Size="Medium" ForeColor="Black"
Text='<%# Eval("Address") + ", " + Eval("Location") %>'>
</asp:Label>
</td>
</tr>
</table>
</td>
</tr>
<tr>
<td>
<asp:Label ID="lblProfile" Font-Size="Medium" ForeColor="Black" runat="server" Text='<%# Eval("CoachProfile") %>'>
</asp:Label>
</td>
</tr>
</table>
</td>
<td>
<%--<asp:Button ID="lnkViewProfile" runat="server" Text="View Profile" PostBackUrl='<%# String.Format("{0} {1}", "~/CoachProfile.aspx?Id=", Eval("CoachId")) %>'>
</asp:Button><br />
<br />--%>
<asp:Button ID="btnMessageCoach" runat="server" Text="Message Coach" Style="border-radius: 5px;
height: 30px; background: #32BC29; width: 180px; font-size: Medium; color: Black;">
</asp:Button>
<cc1:ModalPopupExtender ID="mdMessage" BehaviorID="behaviorIDmp3" runat="server"
PopupControlID="Panel3" TargetControlID="btnMessageCoach" CancelControlID="lnkCancelMessage"
DropShadow="true" BackgroundCssClass="modalBackground">
</cc1:ModalPopupExtender>
<br />
</td>
</tr>
</table>
</ItemTemplate>
</asp:DataList>
<asp:Panel ID="Panel3" runat="server" CssClass="modalPopup" align="center" Style="display: none;
height: 450px; width: 650px;" DefaultButton="btnSendMessage">
<asp:TextBox ID="txtMessage" TextMode="MultiLine" Height="200px" runat="server" class="txtFirstName"
Width="500px" name="email" Font-Size="Large" Style="margin-bottom: 30px; margin-top: 20px;"
ValidationGroup="Message" PlaceHolder="Message" />
<br />
<asp:RequiredFieldValidator EnableClientScript="true" ID="reqtxtMessage" runat="server"
ValidationGroup="Message" ForeColor="Red" ControlToValidate="txtMessage" ErrorMessage="Message Empty"
Display="Dynamic" />
<br />
<asp:TextBox ID="txtContactNumber" runat="server" class="txtFirstName" Width="500px"
name="contactnumber" value="" Height="40px" Font-Size="Medium" PlaceHolder="Contact Number" />
<asp:RequiredFieldValidator EnableClientScript="true" ID="reqtxtContactNumber" runat="server"
ValidationGroup="Message" ForeColor="Red" ControlToValidate="txtContactNumber"
ErrorMessage="Contact Number Empty" Display="Dynamic" />
<br />
<asp:RegularExpressionValidator ID="regtxtContactNumber" runat="server" ControlToValidate="txtContactNumber"
ValidationGroup="Message" ErrorMessage="RegularExpressionValidator" ForeColor="Red"
ValidationExpression="[0-9]{10}" Text="Enter 10 digit mobile number">
</asp:RegularExpressionValidator>
<div>
<asp:Button ID="btnSendMessage" ValidationGroup="Message" runat="server" Text="Send"
Style="border-radius: 5px; height: 35px; background: #32BC29; width: 400px; font-size: Medium;
color: Black; margin-top: 30px; color: Black;" OnClick="btnSendMessage_Click" /></div>
<br />
<asp:HyperLink ID="lnkCancelMessage" runat="server" Text="Cancel" CssClass="btnClosePopup"
Style="margin-top: 10px;">Close</asp:HyperLink>
</asp:Panel>
</td>
</tr>
</table>
解决方案
您需要对代码进行以下更新:
将<asp:Panel ID="Panel3" runat="server"
DataList 移到外部,使其不会被多次渲染。
要在服务器端获取单击项目的 coachId,请执行以下操作:
添加<asp:HiddenField
外部数据列表
<asp:HiddenField ID="hidSelectedID" runat="server" />
在 MessageCoach 按钮上添加 OnClientClick 处理程序以在隐藏字段中设置 id:
<asp:Button ID="btnMessageCoach" runat="server"
OnClientClick="javascript:document.getElementById('<%=hidSelectedID.ClientId%>').value='<%#Eval("CoachId")>';" Text="Message Coach" Style="border-radius: 5px; height: 30px; background: #32BC29; width: 180px; font-size: Medium; color: Black;"></asp:Button>
在 btnSendMessage_Click 句柄内,您可以使用访问隐藏字段值hidSelectedID.Value
推荐阅读
- sql - 让结果显示在同一行?
- c++ - 使用 p4api 获取 Perforce 命令运行的输出
- php - 如何在不关心php中单词之间的空格的情况下替换文本
- java - Gradle 项目同步失败 - Android Studio 3.5.1
- angular - 如何避免 Angular ngClass 中的重复?
- spring-boot - 如何在与 JBoss EAP 中的 EJB 通信的 Spring Boot 应用程序上配置 Oracle XA 数据源
- c# - C# 使用 XSD 验证 XML 而不加载未经验证的 XSD?
- c# - 如何让 Tensorflow PoseNet 与 Xamarin forms/Xam.Android 一起使用
- assembly - MASM 5.1a:警告 A4057 操作数和链接 V2.0 的大小非法:对象模块无效
- android - 拒绝对 OkHttp 中先前失败的类重新初始化