asp.net – 在GridView问题中的ImageButton上的PopUpExtender
发布时间:2020-12-16 00:04:58 所属栏目:asp.Net 来源:网络整理
导读:我的asp.net页面上有GridView,该网格中的一列是ImageButton(TemplateField,ID =“imbReserve”).单击该按钮我想显示PopUp,但是当我把TargetControlId =“imbReserve”时,我收到错误消息“无法找到ID为’imbReserve’的控件”.如何实现这一点,点击Grid里面的
我的asp.net页面上有GridView,该网格中的一列是ImageButton(TemplateField,ID =“imbReserve”).单击该按钮我想显示PopUp,但是当我把TargetControlId =“imbReserve”时,我收到错误消息“无法找到ID为’imbReserve’的控件”.如何实现这一点,点击Grid里面的按钮显示PopUp?
解决方法
看看这两篇文章,只是帮我解决了这个问题
第1条:A More Traditional approach 以下内容将从上述文章中解释 页码: <asp:UpdatePanel ID="updatePanel" runat="server" UpdateMode="Conditional"> <ContentTemplate> <asp:GridView ID="gvCustomers" runat="server" AutoGenerateColumns="false" Width="95%"> <Columns> <asp:TemplateField > <ItemTemplate> <asp:Button ID="btnViewDetails" runat="server" Text="Details" OnClick="BtnViewDetails_Click" /> </ItemTemplate> </asp:TemplateField> <asp:BoundField DataField="customerid" HeaderText="ID" /> <asp:BoundField DataField="companyname" HeaderText="Company" /> <asp:BoundField DataField="contactname" HeaderText="Name" /> <asp:BoundField DataField="contacttitle" HeaderText="Title" /> </Columns> </asp:GridView> </ContentTemplate> </asp:UpdatePanel> <ajaxToolKit:ModalPopupExtender ID="mdlPopup" runat="server" TargetControlID="pnlPopup" PopupControlID="pnlPopup" CancelControlID="btnClose" BackgroundCssClass="modalBackground" /> <asp:Panel ID="pnlPopup" runat="server" Width="500px" style="display:none"> <asp:UpdatePanel ID="updPnlCustomerDetail" runat="server" UpdateMode="Conditional"> <ContentTemplate> [Your Content Here] </ContentTemplate> </asp:UpdatePanel> <div align="right" style="width:95%"> <asp:Button ID="btnSave" runat="server" Text="Save" /> <asp:Button ID="btnClose" runat="server" Text="Close" Width="50px" /> </div> </asp:Panel> 请注意,GridView包含在更新面板中,Modal Extender的目标控件ID与弹出控件ID相同.这是因为ModalPopUp Extender需要一个目标控件ID,我认为这个解决方案比使用隐藏按钮更好. 现在为代码背后: protected void BtnViewDetails_Click(object sender,EventArgs e) { // Do Anything you need to the contents of the update panel // update the contents in the detail panel this.updPnlCustomerDetail.Update(); // show the modal popup this.mdlPopup.Show(); } 第2条:Uses Clientside Javascript 以下内容将从上述文章中解释 客户端Javascript <script type="text/javascript"> // keeps track of the delete button for the row // that is going to be removed var _source; // keep track of the popup div var _popup; function showConfirm(source){ this._source = source; this._popup = $find('mdlPopup'); // find the confirm ModalPopup and show it this._popup.show(); } function okClick(){ // find the confirm ModalPopup and hide it this._popup.hide(); // use the cached button as the postback source __doPostBack(this._source.name,''); } function cancelClick(){ // find the confirm ModalPopup and hide it this._popup.hide(); // clear the event source this._source = null; this._popup = null; } 页码: <asp:GridView ID="gvToDoList" runat="server" AutoGenerateColumns="false" > <Columns> <asp:BoundField DataField="ID" HeaderText="ID" /> <asp:BoundField DataField="Item" HeaderText="Description" /> <asp:BoundField DataField="IsCompleted" HeaderText="Complete?" /> <asp:TemplateField ControlStyle-Width="50px" HeaderStyle-Width="60px" > <ItemTemplate> <asp:Button ID="btnDelete" runat="server" OnClientClick="showConfirm(this); return false;" OnClick="BtnDelete_Click" Text="Delete" /> </ItemTemplate> </asp:TemplateField> </Columns> </asp:GridView> <ajaxToolKit:ModalPopupExtender BehaviorID="mdlPopup" runat="server" TargetControlID="div" PopupControlID="div" OkControlID="btnOk" OnOkScript="okClick();" CancelControlID="btnNo" OnCancelScript="cancelClick();" BackgroundCssClass="modalBackground" /> <div id="div" runat="server" align="center" class="confirm" style="display:none"> <img align="absmiddle" src="Img/warning.jpg" />Are you sure you want to delete this item? <asp:Button ID="btnOk" runat="server" Text="Yes" Width="50px" /> <asp:Button ID="btnNo" runat="server" Text="No" Width="50px" /> </div> 再次注意,Modal Pop Up Extender的目标控件ID与弹出控件ID相同.还要注意模板字段中按钮的OnClientClick属性,确保包含“return false;”. 在其后面的代码中需要使用onClick(或onCommand)事件处理程序来执行您需要执行的操作. 我成功地尝试了这两种方法. 希望这两个中的一个适合你. (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |
相关内容
- 在asp.net应用程序中启用c#7
- asp.net – 在Application_Error中将异常转换为HTTP 404响应
- asp.net-mvc-3 – R#6 – 在剃刀视图中建议“使用目录”.如
- asp.net-mvc-4 – ASP.NET MVC 4会员“记住我”如何运作?
- ASP.NET Core 2.0 Identity中的Cookies.ApplicationCookie.
- asp.net-mvc – 使用MVC 4.0 Web Api的NewtonSoft json Con
- 用ASP.net检测iPad
- mvc项目架构分享系列之架构搭建之Infrastructure
- ASP.NET会话对象中的实体框架对象上下文?
- asp.net-mvc-routing – ASP MVC 5属性路由VS.基于公约的路
推荐文章
站长推荐
- asp.net – ‘InitializeCulture’不是其成员
- asp.net – NHibernate线程安全与会话
- asp.net – 使用WebAPI时重新验证模型(TryValida
- ASP.NET MVC 2中是否存在强类型的RedirectToActi
- 增加ASP.net WebForm性能
- asp.net – WebForms中的异步/等待 – 在页面生命
- asp.net – 为什么有2个web.config文件
- asp.net-mvc-3 – 在MVC3中添加有关打印功能的数
- asp.net – 将Windows身份验证重定向到自定义401
- asp.net-mvc – ASP.NET MVC Json DateTime序列化
热点阅读