Solved

how to get a ajax modelpopupextender to work in vs2010

Posted on 2011-03-01
2
535 Views
Last Modified: 2012-05-11
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
Comment
Question by:bschave2
2 Comments
 
LVL 13

Accepted Solution

by:
agarwalrahul earned 500 total points
Comment Utility

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
 

Author Closing Comment

by:bschave2
Comment Utility
this works, but found out how to do it without a web method.
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Problem Hi all,    While many today have fast Internet connection, there are many still who do not, or are connecting through devices with a slower connect, so light web pages and fast load times are still popular.    If your ASP.NET page …
Entity Framework is a powerful tool to help you interact with the DataBase but still doesn't help much when we have a Stored Procedure that returns more than one resultset. The solution takes some of out-of-the-box thinking; read on!
This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're looking for how to monitor bandwidth using netflow or packet s…
When you create an app prototype with Adobe XD, you can insert system screens -- sharing or Control Center, for example -- with just a few clicks. This video shows you how. You can take the full course on Experts Exchange at http://bit.ly/XDcourse.

771 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now