Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

how to get a ajax modelpopupextender to work in vs2010

Posted on 2011-03-01
2
Medium Priority
?
551 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

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.

Question has a verified solution.

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

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 …
This article is for Object-Oriented Programming (OOP) beginners. An Interface contains declarations of events, indexers, methods and/or properties. Any class which implements the Interface should provide the concrete implementation for each Inter…
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…
Want to learn how to record your desktop screen without having to use an outside camera. Click on this video and learn how to use the cool google extension called "Screencastify"! Step 1: Open a new google tab Step 2: Go to the left hand upper corn…
Suggested Courses

636 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