Solved

how to get a ajax modelpopupextender to work in vs2010

Posted on 2011-03-01
2
539 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
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

ScreenConnect 6.0 Free Trial

At ScreenConnect, partner feedback doesn't fall on deaf ears. We collected partner suggestions off of their virtual wish list and transformed them into one game-changing release: ScreenConnect 6.0. Explore all of the extras and enhancements for yourself!

Question has a verified solution.

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

Suggested Solutions

Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
Performance in games development is paramount: every microsecond counts to be able to do everything in less than 33ms (aiming at 16ms). C# foreach statement is one of the worst performance killers, and here I explain why.
In a recent question (https://www.experts-exchange.com/questions/28997919/Pagination-in-Adobe-Acrobat.html) here at Experts Exchange, a member asked how to add page numbers to a PDF file using Adobe Acrobat XI Pro. This short video Micro Tutorial sh…
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…

803 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