ModalPopupExtender Show()没有触发ASP.NET C# [英] ModalPopupExtender Show() not firing ASP.NET C#

查看:106
本文介绍了ModalPopupExtender Show()没有触发ASP.NET C#的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我知道这个问题已经发布在很多不同的场合。我看了很多网站找到这个问题的解决方案,但是这些解决方案都没有帮我找到正确答案。



我的代码基于在这个人的网站上>>

http://mattberseth.com/blog/2007/07/modalpopupextender_example_for.html [ ^ ]



我有一个GridView,它从SqlDataSource1中获取数据。在GridView中,在第一列中我有View按钮,它们应该显示ModalPopupExtender1中每行的详细信息。我将其TargetControlID设置为btnShowPopup,这是不可见的,但正如我所说的不可见并不意味着它设置为Visible =false但它设置为style =display:none(我发现这是人们做的方式)。



问题是即使我点击其中一个View按钮,ModalPopup也没有出现。实际上,当我单击按钮时,没有任何反应。



在Visual Basic上,单击查看按钮后,我看不到任何错误消息或异常处理程序。



任何帮助将不胜感激。提前谢谢!



我的代码:



< aspx>

I know this issue has been posted on many different occasions. I've looked so many websites to find a solution to this issue, however none of those solutions have helped me find the correct answer to this.

My code is based on this guy's website>>
http://mattberseth.com/blog/2007/07/modalpopupextender_example_for.html[^]

I have a GridView that sources its data from the SqlDataSource1. Within that GridView, in the first column I have View buttons that should show the details of each row in the ModalPopupExtender1. I set its TargetControlID to btnShowPopup, which is not visible but as I say "not visible" doesn't mean it's set Visible= "false" but it is set style="display:none" (I found this is the way people do).

The problem is even when I click on one of the View buttons, the ModalPopup doesn't appear. In fact, when I click the button, nothing happens.

On the Visual Basic, I don't see any error messages nor exception handlers after clicking on the View button.

Any help would be appreciated. Thank you in advance!

My code:

<aspx>

<%@ Page Title="" Language="C#" MasterPageFile="~/Main/MasterPage.master" AutoEventWireup="true" CodeFile="SearchAcquisition.aspx.cs" Inherits="PosStock" %>

<%@ Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" TagPrefix="asp" %>



<asp:Content ID="Content1" ContentPlaceHolderID="headContent" Runat="Server">
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="Maincontent" Runat="Server">
    
        <div class="contentboxh">
        <h2 class="hpos">Acquisition Search</h2>
            <br />
            <br />
            <h2 class="h4" style="text-align: left">Search</h2>
            <br />

             <asp:TextBox ID="SearchField" runat="server" Width="350px" Height="30px" OnTextChanged="SearchField_TextChanged"></asp:TextBox>
            <asp:Button ID="SearchButton" runat="server" Text="Search" Height="26px" OnClick="SearchButton_Click" BackColor="#7AB800" CssClass="searchbutton" />
       
        </div>
        <div class="contentboxh">
            <asp:ScriptManager ID="ScriptManager1" runat="server">
            </asp:ScriptManager>
            <asp:SqlDataSource ID="SqlDataSource1" runat="server" SelectCommand="SELECT [acquisition_ID], [acquisition_name], [acquisition_qty], [acquisition_cost], [acquisition_date], [acquisition_status] FROM [Acquisition] WHERE [acquisition_ID] = @acquisition_ID"

                SelectCommandType="Text" CancelSelectOnNullParameter="true" ConnectionString="<%$ ConnectionStrings:MJENTAConnectionString %>"></asp:SqlDataSource>

            <asp:UpdatePanel ID="updatePanel" runat="server" UpdateMode="Conditional">
                <ContentTemplate>
                    <asp:GridView ID="GridView1" runat="server" DataKeyNames="acquisition_ID" AutoGenerateColumns="false" AllowPaging="true" AllowSorting="true" PageSize="10" Width="95%">
                        <Columns>
                            <asp:TemplateField ControlStyle-Width="50px" HeaderStyle-Width="60px">
                                <ItemTemplate>
                                    <asp:Button ID="btnViewDetails" runat="server" Text="Details" CommandName="View" OnClick="BtnViewDetails_Click" />
                                </ItemTemplate>
                            </asp:TemplateField>
                            <asp:BoundField DataField="acquisition_ID" HeaderText="ID" SortExpression="acquisition_ID" ReadOnly="true" />
                            <asp:BoundField DataField="acquisition_name" HeaderText="Name" SortExpression="acquisition_name" ReadOnly="true" />
                            <asp:BoundField DataField="acquisition_qty" HeaderText="Quantity" SortExpression="acquisition_qty" ReadOnly="true" />
                            <asp:BoundField DataField="acquisition_cost" HeaderText="Cost" SortExpression="acquisition_cost" ReadOnly="true" />
                            <asp:BoundField DataField="acquisition_date" HeaderText="Date Added" SortExpression="acquisition_date" ReadOnly="true" />
                            <asp:BoundField DataField="acquisition_status" HeaderText="Status" SortExpression="acquisition_status" ReadOnly="true" />
                        </Columns>
                    </asp:GridView>
                </ContentTemplate>
            </asp:UpdatePanel>


            <asp:Button ID="btnShowPopup" runat="server" style="display:none" />
            <asp:ModalPopupExtender ID="ModalPopupExtender1" runat="server" TargetControlID="btnShowPopup" PopupControlID="pnlPopup"

                            CancelControlID="btnClose" BackgroundCssClass="modalBackground" />

            <asp:Panel ID="pnlPopup" runat="server" CssClass="detail" Width="500px" style="display:none">
                <asp:UpdatePanel ID="updPnlCustomerDetail" runat="server" UpdateMode="Conditional">
                    <ContentTemplate>
                        <asp:Label ID="lblCustomerDetail" runat="server" Text="Detail" BackColor="LightBlue" Width="95%" />
                        <asp:DetailsView ID="DetailsView1" runat="server" DefaultMode="Edit" Width="95%" BackColor="White" />
                    </ContentTemplate>
                </asp:UpdatePanel>
                <div align="right" style="width:95%">
                    <asp:Button ID="btnSave" runat="server" Text="Save" Width="50px" />
                    <asp:Button ID="btnClose" runat="server" Text="Close" Width="50px" />
                </div>
            </asp:Panel>
        </div>
</asp:Content>







<br />
<pre lang="c#"><br />
using System;<br />
using System.Collections.Generic;<br />
using System.Linq;<br />
using System.Web;<br />
using System.Web.UI;<br />
using System.Web.Security;<br />
using System.Web.UI.HtmlControls;<br />
using System.Web.UI.WebControls;<br />
using System.Web.UI.WebControls.WebParts;<br />
using System.Configuration;<br />
using System.Data.SqlClient;<br />
using System.Data.SqlTypes;<br />
using System.Data;<br />
<br />
public partial class PosStock : System.Web.UI.Page<br />
{<br />
    protected void Page_Load(object sender, EventArgs e)<br />
    {<br />
        <br />
    }<br />
    protected void BtnViewDetails_Click(object sender, EventArgs e)<br />
    {<br />
        Button btnDetails = sender as Button;<br />
        GridViewRow row = (GridViewRow)btnDetails.NamingContainer;<br />
<br />
        this.SqlDataSource1.SelectParameters.Clear();<br />
        this.SqlDataSource1.SelectParameters.Add("acquisition_ID", Convert.ToString(this.GridView1.DataKeys[row.RowIndex].Value));<br />
        this.DetailsView1.DataSource = this.SqlDataSource1;<br />
        this.DetailsView1.DataBind();<br />
<br />
        this.updPnlCustomerDetail.Update();<br />
        ModalPopupExtender1.Show();<br />
<br />
    }<br />
    protected void SearchField_TextChanged(object sender, EventArgs e)<br />
    {<br />
<br />
    }<br />
    protected void SearchButton_Click(object sender, EventArgs e)<br />
    {<br />
        SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["MJENTAConnectionString"].ToString());<br />
<br />
        SqlCommand cmd;<br />
        <br />
        String str = "SELECT acquisition_ID, acquisition_name, acquisition_qty, acquisition_cost, acquisition_date, acquisition_status FROM Acquisition WHERE (acquisition_name like '%' + @search + '%')";<br />
        cmd = new SqlCommand(str, con);<br />
        cmd.Parameters.Add("@search", SqlDbType.NVarChar).Value = SearchField.Text;<br />
        con.Open();<br />
        cmd.ExecuteNonQuery();<br />
        SqlDataAdapter da = new SqlDataAdapter();<br />
        da.SelectCommand = cmd;<br />
        DataSet ds = new DataSet();<br />
        da.Fill(ds, "acquisition_name");<br />
        GridView1.DataSource = ds;<br />
        GridView1.DataBind();<br />
        con.Close();<br />
    }<br />
}<br />
</pre>

推荐答案

ConnectionStrings:MJENTAConnectionString %>\"></asp:SqlDataSource>

<asp:UpdatePanel ID=\"updatePanel\" runat=\"server\" UpdateMode=\"Conditional\">
<ContentTemplate>
<asp:GridView ID=\"GridView1\" runat=\"server\" DataKeyNames=\"acquisition_ID\" AutoGenerateColumns=\"false\" AllowPaging=\"true\" AllowSorting=\"true\" PageSize=\"10\" Width=\"95%\">
<Columns>
<asp:TemplateField ControlStyle-Width=\"50px\" HeaderStyle-Width=\"60px\">
<ItemTemplate>
<asp:Button ID=\"btnViewDetails\" runat=\"server\" Text=\"Details\" CommandName=\"View\" OnClick=\"BtnViewDetails_Click\" />
</ItemTemplate>
</asp:TemplateField>
<asp:BoundField Da taField=\"acquisition_ID\" HeaderText=\"ID\" SortExpression=\"acquisition_ID\" ReadOnly=\"true\" />
<asp:BoundField DataField=\"acquisition_name\" HeaderText=\"Name\" SortExpression=\"acquisition_name\" ReadOnly=\"true\" />
<asp:BoundField DataField=\"acquisition_qty\" HeaderText=\"< span class=\"code-keyword\">Quantity\" SortExpression=\"acquisition_qty\" ReadOnly=\"true\" />
<asp:BoundField DataField=\"acquisition_cost\" HeaderText=\"Cost\" SortExpression=\"acquisition_cost\" ReadOnly=\"true\" />
<asp:BoundField DataField=\"acquisition_date\" HeaderText=\"Date Added\" SortExpression=\"acquisition_date\" ReadOnly=\"true\" />
<asp:BoundField DataField=\"acquisition_status\" HeaderText=\"Status\" SortExpression=\"acquisition_status\" ReadOnly=\"true\" />
</Columns>
</asp:GridView>
</ContentTemplate>
</asp:UpdatePanel>


<asp:Button ID=\"btnShowPopup\" runat=\"server\" style=\"display:none\" />
<asp:ModalPopupExtender ID=\"ModalPopupExtender1\" runat=\"server\" TargetCon trolID=\"btnShowPopup\" PopupControlID=\"pnlPopup\"

CancelControlID=\"btnClose\" BackgroundCssClass=\"modalBackground\" />

<asp:Panel ID=\"pnlPopup\" runat=\"server\" CssClass=\"detail\" Width=\"500px\" style=\"display:none\">
<asp:UpdatePanel ID=\"updPnlCustomerDet ail\" runat=\"server\" UpdateMode=\"Conditional\">
<ContentTemplate>
<asp:Label ID=\"lblCustomerDetail\" runat=\"server\" Text=\"Detail\" BackColor=\"LightBlue\" Width=\"95%\" />
<asp:DetailsView ID=\"DetailsView1\" runat=\"server\" DefaultMode=\"Edit\" Width=\"95%\" BackColor=\"White\" />
</ContentTemplate>
</asp:UpdatePanel>
<div align=\"right\" style=\"width:95%\">
<asp:Button ID=\"btnSave\" runat=\"server\" Text=\"Save\" Width=\" 50px\" />
<asp:Button ID=\"btnClose\" runat=\"server\" Text=\"Close\" Width=\"50px\" />
</div>
</asp:Panel>
</div>
</asp:Content>
ConnectionStrings:MJENTAConnectionString %>"></asp:SqlDataSource> <asp:UpdatePanel ID="updatePanel" runat="server" UpdateMode="Conditional"> <ContentTemplate> <asp:GridView ID="GridView1" runat="server" DataKeyNames="acquisition_ID" AutoGenerateColumns="false" AllowPaging="true" AllowSorting="true" PageSize="10" Width="95%"> <Columns> <asp:TemplateField ControlStyle-Width="50px" HeaderStyle-Width="60px"> <ItemTemplate> <asp:Button ID="btnViewDetails" runat="server" Text="Details" CommandName="View" OnClick="BtnViewDetails_Click" /> </ItemTemplate> </asp:TemplateField> <asp:BoundField DataField="acquisition_ID" HeaderText="ID" SortExpression="acquisition_ID" ReadOnly="true" /> <asp:BoundField DataField="acquisition_name" HeaderText="Name" SortExpression="acquisition_name" ReadOnly="true" /> <asp:BoundField DataField="acquisition_qty" HeaderText="Quantity" SortExpression="acquisition_qty" ReadOnly="true" /> <asp:BoundField DataField="acquisition_cost" HeaderText="Cost" SortExpression="acquisition_cost" ReadOnly="true" /> <asp:BoundField DataField="acquisition_date" HeaderText="Date Added" SortExpression="acquisition_date" ReadOnly="true" /> <asp:BoundField DataField="acquisition_status" HeaderText="Status" SortExpression="acquisition_status" ReadOnly="true" /> </Columns> </asp:GridView> </ContentTemplate> </asp:UpdatePanel> <asp:Button ID="btnShowPopup" runat="server" style="display:none" /> <asp:ModalPopupExtender ID="ModalPopupExtender1" runat="server" TargetControlID="btnShowPopup" PopupControlID="pnlPopup" CancelControlID="btnClose" BackgroundCssClass="modalBackground" /> <asp:Panel ID="pnlPopup" runat="server" CssClass="detail" Width="500px" style="display:none"> <asp:UpdatePanel ID="updPnlCustomerDetail" runat="server" UpdateMode="Conditional"> <ContentTemplate> <asp:Label ID="lblCustomerDetail" runat="server" Text="Detail" BackColor="LightBlue" Width="95%" /> <asp:DetailsView ID="DetailsView1" runat="server" DefaultMode="Edit" Width="95%" BackColor="White" /> </ContentTemplate> </asp:UpdatePanel> <div align="right" style="width:95%"> <asp:Button ID="btnSave" runat="server" Text="Save" Width="50px" /> <asp:Button ID="btnClose" runat="server" Text="Close" Width="50px" /> </div> </asp:Panel> </div> </asp:Content>







<br />
<pre lang="c#"><br />
using System;<br />
using System.Collections.Generic;<br />
using System.Linq;<br />
using System.Web;<br />
using System.Web.UI;<br />
using System.Web.Security;<br />
using System.Web.UI.HtmlControls;<br />
using System.Web.UI.WebControls;<br />
using System.Web.UI.WebControls.WebParts;<br />
using System.Configuration;<br />
using System.Data.SqlClient;<br />
using System.Data.SqlTypes;<br />
using System.Data;<br />
<br />
public partial class PosStock : System.Web.UI.Page<br />
{<br />
    protected void Page_Load(object sender, EventArgs e)<br />
    {<br />
        <br />
    }<br />
    protected void BtnViewDetails_Click(object sender, EventArgs e)<br />
    {<br />
        Button btnDetails = sender as Button;<br />
        GridViewRow row = (GridViewRow)btnDetails.NamingContainer;<br />
<br />
        this.SqlDataSource1.SelectParameters.Clear();<br />
        this.SqlDataSource1.SelectParameters.Add("acquisition_ID", Convert.ToString(this.GridView1.DataKeys[row.RowIndex].Value));<br />
        this.DetailsView1.DataSource = this.SqlDataSource1;<br />
        this.DetailsView1.DataBind();<br />
<br />
        this.updPnlCustomerDetail.Update();<br />
        ModalPopupExtender1.Show();<br />
<br />
    }<br />
    protected void SearchField_TextChanged(object sender, EventArgs e)<br />
    {<br />
<br />
    }<br />
    protected void SearchButton_Click(object sender, EventArgs e)<br />
    {<br />
        SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["MJENTAConnectionString"].ToString());<br />
<br />
        SqlCommand cmd;<br />
        <br />
        String str = "SELECT acquisition_ID, acquisition_name, acquisition_qty, acquisition_cost, acquisition_date, acquisition_status FROM Acquisition WHERE (acquisition_name like '%' + @search + '%')";<br />
        cmd = new SqlCommand(str, con);<br />
        cmd.Parameters.Add("@search", SqlDbType.NVarChar).Value = SearchField.Text;<br />
        con.Open();<br />
        cmd.ExecuteNonQuery();<br />
        SqlDataAdapter da = new SqlDataAdapter();<br />
        da.SelectCommand = cmd;<br />
        DataSet ds = new DataSet();<br />
        da.Fill(ds, "acquisition_name");<br />
        GridView1.DataSource = ds;<br />
        GridView1.DataBind();<br />
        con.Close();<br />
    }<br />
}<br />
</pre>


Hi


Try using Toolkit Script Manger instead of ScriptManager



Thanks
Hi
Try using Toolkit Script Manger instead of ScriptManager

Thanks


这篇关于ModalPopupExtender Show()没有触发ASP.NET C#的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆