• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 552
  • Last Modified:

how to get a ajax modelpopupextender to work in vs2010

I am trying to create a gridview that pops up a modal window with the edit button and passes the id through a onclick event. This is the problem. I have tried ALL of the crappy examples of this online, so please do not forward me to a link for an example. This does not work! my code is below. I have attached my aspx file which uses a master page and my .cs file. Any useful help would be greatly appreciated.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;

namespace CallOptionsAvailability
{
    public partial class userMgt : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
             
            Session["USER_ID"] = HttpContext.Current.User.Identity.Name;

            btnSave.OnClientClick = String.Format("functionPostback('{0}','{1}')", btnSave.UniqueID, "");
            if(!IsPostBack)
            {
                Worker.getManageUsersGV(userGV);
            }
        }

        protected void btnSave_Click(object sender, EventArgs e)
        {
            txtEmail.Text = "";
        }

        protected void btnEdit_Click(object sender, EventArgs e)
        {
            GridViewRow row = ((GridViewRow)((Button)sender).NamingContainer);
            //string id = userGV.SelectedDataKey.Value.ToString();
            //string send = sender.ToString();
            //NamingContainer return the container that the control sits in
            AjaxControlToolkit.ModalPopupExtender mpe = (AjaxControlToolkit.ModalPopupExtender)row.FindControl("mpe");      
            mpe.Show(); //show the modal popup extender
            //Response.Write(row);
        }

        protected void btnDelete_Click(object sender, EventArgs e)
        {

        }

        protected void btnCancel_Click(object sender, EventArgs e)
        {
            GridViewRow row = ((GridViewRow)((Button)sender).NamingContainer);
            AjaxControlToolkit.ModalPopupExtender mpe = (AjaxControlToolkit.ModalPopupExtender)row.FindControl("mpe");
            mpe.Hide(); //show the modal popup extender
        }

        protected void btnPop_Click(object sender, EventArgs e)
        {

        }

        protected void editCmd(object sender, CommandEventArgs e)
        {
            int id = 5;
        }

    }
}

Open in new window

<%@ Page Title="" Language="C#" MasterPageFile="~/siteStandard.Master" AutoEventWireup="true" CodeBehind="userMgt.aspx.cs" Inherits="CallOptionsAvailability.userMgt" %>

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

<asp:Content ID="Content1" ContentPlaceHolderID="title" runat="server">
    External User Management
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="head" runat="server">
    <script type="text/javascript">
        function fnClickUpdate(sender, e) {
            __doPostBack(sender, e);
        }
</script>            
</asp:Content>
<asp:Content ID="Content3" ContentPlaceHolderID="ContentPlaceHolder1" runat="server">
    <asp:ScriptManager ID="ScriptManager1" runat="server">
    </asp:ScriptManager>
    
    <h2>External User Management</h2>
    <asp:GridView ID="userGV" runat="server" HorizontalAlign="Left" 
    Width="920px" Font-Size="12px" AutoGenerateColumns="False" 
    DataKeyNames="EMAILADDRESS" BackColor="White" BorderColor="#DEDFDE" 
    BorderStyle="None" BorderWidth="1px" CellPadding="4" 
    EnablePersistedSelection="True" ForeColor="Black" GridLines="Vertical">
        <AlternatingRowStyle BackColor="White" />
        <Columns>
            <asp:TemplateField>
                <ItemTemplate>
                    <asp:Button ID="btnEdit" runat="server" Text="Edit" OnClick="btnEdit_Click" CommandArgument='<%Eval("EMailaddress") %>' OnCommand="editCmd" />
                    <asp:Button ID="btnDelete" runat="server" Text="Delete" onclick="btnDelete_Click" />
                    <asp:Button ID="btnPop" runat="server" Text="" onclick="btnPop_Click" style="display:none;" />
                    <asp:ModalPopupExtender ID="mpe" runat="server" TargetControlID="btnPop" 
                    PopupControlID="popUp"  
                    BackgroundCssClass="modalBG" DropShadow="true">
                    </asp:ModalPopupExtender>
                </ItemTemplate>
            </asp:TemplateField>
            <asp:BoundField DataField="EMAILADDRESS" HeaderText="Email Address" ReadOnly="True" SortExpression="EmailID"/>
            <asp:BoundField DataField="TRADESCOMPANYID" HeaderText="Company ID" ReadOnly="True" SortExpression="CompanyID"/>
            <asp:BoundField DataField="FIRSTNAME" HeaderText="First Name" ReadOnly="True" SortExpression="FirstName"/>
            <asp:BoundField DataField="MIDDLEINITIAL" HeaderText="Middle Initial" ReadOnly="True" SortExpression="MiddleI"/>
            <asp:BoundField DataField="LASTNAME" HeaderText="LastName" ReadOnly="True" SortExpression="LastName"/>
        </Columns>
        <FooterStyle BackColor="#CCCC99" />
        <HeaderStyle BackColor="#6B696B" Font-Bold="True" ForeColor="White" />
        <PagerStyle BackColor="#F7F7DE" ForeColor="Black" HorizontalAlign="Right" />
        <RowStyle BackColor="#F7F7DE" />
        <SelectedRowStyle BackColor="#CE5D5A" Font-Bold="True" ForeColor="White" />
        <SortedAscendingCellStyle BackColor="#FBFBF2" />
        <SortedAscendingHeaderStyle BackColor="#848384" />
        <SortedDescendingCellStyle BackColor="#EAEAD3" />
        <SortedDescendingHeaderStyle BackColor="#575357" />
    </asp:GridView>
    <div id="popUp" style="width:550px;padding:30px;height:400px;margin-top:-50px;z-index:10000;display:none;background:#fff;">
        <h2>Edit External User</h2>
        <table class="ModalTbl">
            <tr>
                <td>
                    Name Suffix:
                </td>
                <td>
                    <asp:DropDownList ID="ddNameSuffix" runat="server">
                        <asp:ListItem Text="Mr." Value="1"></asp:ListItem>
                        <asp:ListItem Text="Ms." Value="2"></asp:ListItem>
                        <asp:ListItem Text="Mrs." Value="3"></asp:ListItem>
                        <asp:ListItem Text="II" Value="4"></asp:ListItem>
                        <asp:ListItem Text="III" Value="5"></asp:ListItem>
                    </asp:DropDownList>
                </td>
            </tr>
            <tr>
                <td>
                    First Name:
                </td>
                <td>
                    <asp:TextBox ID="txtFName" runat="server"></asp:TextBox>
                </td>
            </tr>
            <tr>
                <td>
                    Middle Initial: 
                </td>
                <td>
                    <asp:TextBox ID="txtMI" runat="server"></asp:TextBox>
                </td>
            </tr>
            <tr>
                <td>
                    Last Name: 
                </td>
                <td>
                    <asp:TextBox ID="txtLName" runat="server"></asp:TextBox>
                </td>
            </tr>
            <tr>
                <td>
                    Trades Company ID: 
                </td>
                <td>
                    <asp:Label ID="lblTradesId" runat="server" Text="Label"></asp:Label>
                </td>
            </tr>
            <tr>
                <td>
                    Phone Number: 
                </td>
                <td>
                    <asp:TextBox ID="txtPhone" runat="server"></asp:TextBox>
                </td>
            </tr>
            <tr>
                <td>
                    Reset Password?:
                </td>
                <td>
                    <asp:CheckBox ID="chkResetPW" runat="server" />
                </td>
            </tr>
            <tr>
                <td>
                    Email Address: 
                </td>
                <td>
                    <asp:TextBox ID="txtEmail" runat="server"></asp:TextBox>
                </td>
            </tr>
            <tr>
                <td>
                    
                </td>
                <td>
                    <asp:Button ID="btnSave" runat="server" Text="Save" onclick="btnSave_Click" />
                    <asp:Button ID="btnCancel" runat="server" Text="Cancel" />
                </td>
            </tr>
        </table>
    </div>
    <asp:Button ID="btnPop" runat="server" Text="Button" Visible="false" />
</asp:Content>

Open in new window

0
bschave2
Asked:
bschave2
1 Solution
 
Rahul AgarwalTeam LeaderCommented:

Script Manager:

 <asp:ScriptManager ID="ScriptManager2" runat="server">
        <services>
            <asp:ServiceReference Path="WebService.asmx"  />
        </services>
    </asp:ScriptManager>

code behind:

If (e.Row.RowType = DataControlRowType.DataRow) Then
             
                hl = CType(e.Row.FindControl("hlEdit"), HyperLink)
                hl.Attributes.Add("OnClick", "ShowMyModalPopup('" + gridview1.DataKeys(e.Row.RowIndex).Value + "')")
               
            End If


Attach the javascript function on gridview_rowdatabound event where rowtype is Datarow and when you click on edit button on gridview then it fetch the data from webservice with the help of gridview datakeys, then you can do your stuff accordingly. code.txt
0
 
bschave2Author Commented:
this works, but found out how to do it without a web method.
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now