Click here to Skip to main content
15,886,518 members
Please Sign up or sign in to vote.
5.00/5 (2 votes)
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>
ASP.NET
<%@ 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>



C#
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.Security;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Configuration;
using System.Data.SqlClient;
using System.Data.SqlTypes;
using System.Data;

public partial class PosStock : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        
    }
    protected void BtnViewDetails_Click(object sender, EventArgs e)
    {
        Button btnDetails = sender as Button;
        GridViewRow row = (GridViewRow)btnDetails.NamingContainer;

        this.SqlDataSource1.SelectParameters.Clear();
        this.SqlDataSource1.SelectParameters.Add("acquisition_ID", Convert.ToString(this.GridView1.DataKeys[row.RowIndex].Value));
        this.DetailsView1.DataSource = this.SqlDataSource1;
        this.DetailsView1.DataBind();

        this.updPnlCustomerDetail.Update();
        ModalPopupExtender1.Show();

    }
    protected void SearchField_TextChanged(object sender, EventArgs e)
    {

    }
    protected void SearchButton_Click(object sender, EventArgs e)
    {
        SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["MJENTAConnectionString"].ToString());

        SqlCommand cmd;
        
        String str = "SELECT acquisition_ID, acquisition_name, acquisition_qty, acquisition_cost, acquisition_date, acquisition_status FROM Acquisition WHERE (acquisition_name like '%' + @search + '%')";
        cmd = new SqlCommand(str, con);
        cmd.Parameters.Add("@search", SqlDbType.NVarChar).Value = SearchField.Text;
        con.Open();
        cmd.ExecuteNonQuery();
        SqlDataAdapter da = new SqlDataAdapter();
        da.SelectCommand = cmd;
        DataSet ds = new DataSet();
        da.Fill(ds, "acquisition_name");
        GridView1.DataSource = ds;
        GridView1.DataBind();
        con.Close();
    }
}
Posted
Updated 20-Oct-14 20:17pm
v3
Comments
Praveen_P 21-Oct-14 2:18am    
try using Toolkit Script Manger instead of ScriptManager
ThatGuy7 21-Oct-14 2:29am    
OHHHHHHHHH MY GOD!!!!!!!
YOU ARE ABSOLUTELY A GOD!!!!!!!!
I have been stuck on this bug for the last one week and it is FIXED!!
You have just saved my life!! Thank you so much!!
Member 10154533 26-May-16 16:54pm    
WHAAAAAAAAT!!! UNBELIEVABLE -IT WORKED!!!
Thank you very much Sir!!
Praveen_P 8-Jun-16 4:55am    
:) Thankyou
Praveen_P 21-Oct-14 2:45am    
plz accept my solution..

1 solution

Hi
Try using Toolkit Script Manger instead of ScriptManager

Thanks
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900