在Modalpopupextender内部的Datalist按钮中没有触发
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了在Modalpopupextender内部的Datalist按钮中没有触发相关的知识,希望对你有一定的参考价值。
我有一个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,请执行以下操作:
在DataList外添加<asp:HiddenField
<asp:HiddenField ID="hidSelectedID" runat="server" />
添加OnClientClick处理程序onMessage Coach按钮以在隐藏字段中设置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
访问隐藏的字段值
以上是关于在Modalpopupextender内部的Datalist按钮中没有触发的主要内容,如果未能解决你的问题,请参考以下文章
Asp ModalPopupExtender 不显示详细视图
使用 ModalPopupextender 作为弹出窗口打开时调整 iframe 高度的问题
ASP.net 中菜单和 ajax ModalPopupExtender 的 Z-index 问题
按钮单击事件未触发,但 modalpopupextender 正在工作