asp.net – 在GridView问题中的ImageButton上的PopUpExtender

我的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)事件处理程序来执行您需要执行的操作.

我成功地尝试了这两种方法.

希望这两个中的一个适合你.

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐


判断URL文件是不是在于在。private static bool UrlIsExist(string url){ System.Uri u = null; try { u = new Uri(url); } catch { return false; } bool isExist = false;
由于在.net中,Request时出现有HTML或Javascript等字符串时,系统会认为是危险性值。立马报错。解决方案一:在.aspx文件头中加入这句:解决方案二:修改web.config文件:因为validateRequest默认值为true。只要设为false即可。
public static bool ProcessIdCard(this string idCard, out DateTime birthday, out string genderName) { bool result; birthda...
如果你在GridView控件上设置 AllowPaging=&quot;true&quot; or AllowSorting=&quot;true&quot; 而没有使用使用数据源控件 DataSource (i.e. SqlDataSource, ObjectDataSource),运行则会出现下
protected void Page_Load(object sender, EventArgs e){ ScriptManager sm = Page.Master.FindControl(&quot;ScriptManager1&quot;) as ScriptManager; if (sm
1. install all features in IIS2. Try the following steps to register it.run %windir%\Microsoft.NET\Framework\v4.0.21006\aspnet_regiis.exe -i或运行,跳出如下错误
一般来说一个 HTML 文档有很多标签,比如“”、“”、“”等,想把文档中的 img 标签提取出来并不是一件容易的事。由于 img 标签样式变化多端,使提取的时候用程序寻找并不容易。于是想要寻找它们就必须写一个非常健全的正则表达式,不然有可能会找得不全,或者找出来的不是正确的 img 标签。我们可以
asp.net updatepanel 局部刷新,导致JS不能加载,而无法使用,而且 updatepanel会刷两次,郁闷的。解决方法如下:
FileHandlerhttp://www.cnblogs.com/vipsoft/p/3627709.htmlUpdatePanel无法导出下载文件:http://www.cnblogs.com/vipsoft/p/3298299.html//相对路径下载。path: ~/DownLoad///p
本地能上传文件,部署到服务器上就报Cannot access a closed file 错误,以下是解决方法: 最重要是requestLengthDiskThreshold此属性设置输入流缓冲阈值。
http://tool.oschina.net/commons字符十进制转义字符&quot;&amp;#34;&amp;quot;&amp;&amp;#38;&amp;amp;&amp;#62;&amp;gt;不断开空格(non-breaking space)&amp;#160;HTML特殊转义字符
1、2两步为推荐做法1. 将MySql.Data.dll放到 bin目录下面,或都安装mysql-connector-net-6.0.0.msi2.web.config 添加如下节点,注册版本号一致 3.全局配置在C:\WINDOWS\Microsoft.NET\Framework\v2.0.507
C# 跳转新页面string url = &quot;http://www.vipsoft.com.cn&quot;;ResponseRedirect.Redirect(Response, url, &quot;_blank&quot;, &quot;&#39;toolbar=0,scrollbar
.NET Core 在其上下文中,该请求的地址无效。 看了端口,发现没被占用,后来发现是IP地址变了 改成正确的IP就可以了。
datatable是一个jquery扩展的表格插件。其提供了强大的表格功能。官方地址:http://www.datatables.net/在官方示例中,对于表格的是否可排序是在初始化中设置的一个值来决定的$(&quot;.datatable-simplified&quot;).dataTable(
Html table 细边框 导航页档 军事 历史 ...
C# 跳转新页面判断URL文件是不是在于在。C# 指定物理目录下载文件,Response.End导致“正在中止线程”异常的问题public class FileHandler { public static bool DownLoadFile(string path, string fileName
由于将IE11升级到了 11 之前的网站无法正常使用,如果是开发人员碰到之问题,使用了微软的asp.net 控件,那么将服务器的.net framework 升级到 4.5http://www.microsoft.com/en-us/download/details.aspx?id=30653如果浏
引言 本文从Linux小白的视角, 在CentOS 7.x服务器上搭建一个Nginx-Powered AspNet Core Web准生产应用。 在开始之前,我们还是重温一下部署原理,正如你所常见的.Net Core 部署图: 在Linux上部署.Net Core App最好的方式是在Linux机器