?
Solved

how to get a ajax modelpopupextender to work in vs2010

Posted on 2011-03-01
2
Medium Priority
?
545 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 13

Accepted Solution

by:
Rahul Agarwal earned 2000 total points
ID: 35014042

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
ID: 35101529
this works, but found out how to do it without a web method.
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

We all know that functional code is the leg that any good program stands on when it comes right down to it, however, if your program lacks a good user interface your product may not have the appeal needed to keep your customers happy. This issue can…
A quick way to get a menu to work on our website, is using the Menu control and assign it to a web.sitemap using SiteMapDataSource. Example of web.sitemap file: (CODE) Sample code to add to the page menu: (CODE) Running the application, we wi…
NetCrunch network monitor is a highly extensive platform for network monitoring and alert generation. In this video you'll see a live demo of NetCrunch with most notable features explained in a walk-through manner. You'll also get to know the philos…
In this video, Percona Solutions Engineer Barrett Chambers discusses some of the basic syntax differences between MySQL and MongoDB. To learn more check out our webinar on MongoDB administration for MySQL DBA: https://www.percona.com/resources/we…
Suggested Courses

764 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