Can't find the value of a textbox on a ModalPopupExtender

Hi

My code below works apart from it can't find what I type into the textbox on the modal popup.

I'm using some code to have a modal popup on every line of a gridview.
When I click the link in any of the rows then the modal will appear.
The modal has a textbox and a save button.

How do I find out what text I enter in the textbox when I click save?

It would be in the btnSaveClick event handler.

thanks
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>

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

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title>Untitled Page</title>
</head>
<body>
    <form id="form1" runat="server">
        <asp:ScriptManager ID="ScriptManager1" runat="server" />
        
        
        
        <asp:Label ID="lblTest" runat="server">this is a test</asp:Label>
        
        <asp:Button ID="button1" runat="server" Text="First Modal Popup" /> 
        
        <asp:UpdatePanel ID="updatePanel" runat="server">
        </asp:UpdatePanel>
        
        
        <asp:GridView ID="Grd" runat="server" AutoGenerateColumns="false" OnSelectedIndexChanged="Grd_SelectedIndexChanged">                
            <Columns>                    
                <asp:TemplateField>                        
                    <ItemTemplate>                            
                        <asp:LinkButton ID="lblPerson" runat="server" Text='<%# Eval("PersonName") %>' />                            
                        <asp:Panel ID="pnlPerson" runat="server" Style="display: none" Width="400px" Height="400px" BackColor="CadetBlue">
                            <div style="float: right;">
                            <asp:LinkButton ID="lnkClose" runat="server">Close</asp:LinkButton>
                            <asp:Button ID="btnSave" runat="server" OnClick="btnSaveClick" Text="Save" />
                            </div>
                            <asp:TextBox ID="tbName" runat="server"></asp:TextBox>
                        </asp:Panel>
                        <cc1:ModalPopupExtender ID="extPerson" runat="server" TargetControlID="lblPerson" PopupControlID="pnlPerson" DropShadow="true" CancelControlID="lnkClose" OkControlID="btnSave" />
                    </ItemTemplate>
                </asp:TemplateField>
            </Columns>
        </asp:GridView>
        
        <div>
        </div>
    </form>
</body>
</html>








using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using AjaxControlToolkit;

public partial class _Default : System.Web.UI.Page 
{

    protected void Page_Load(object sender, EventArgs e)
    {



        if (!this.IsPostBack) { 
            this.Grd.DataSource = CreateDS(); 
            this.Grd.DataBind(); 
        }



        

    }


    protected void Grd_SelectedIndexChanged(object sender, EventArgs e) { 
        GridViewRow row = ((GridView)sender).SelectedRow; 
        if (row == null) return; 
        ModalPopupExtender extender = row.FindControl("extPerson") as ModalPopupExtender; 
        if (extender != null) {
            extender.Show(); 
        } 
    }


    protected void btnSaveClick(object sender, EventArgs e)
    {
        Button button1 = (Button)sender;
        //TextBox tbName = ((ImageButton)(e.Item.FindControl("tbName")));


        
    }




    
    private DataSet CreateDS() {
        DataSet ds = new DataSet(); 
        if (Session["ds"] == null) 
        { 
            DataTable dt = new DataTable("PersonData"); 
            DataRow dr; 
            dt.Columns.Add(new DataColumn("Person_ID", typeof(Int32))); 
            dt.Columns.Add(new DataColumn("PersonName", typeof(string))); 
            dt.Columns.Add(new DataColumn("Company", typeof(string))); 
            
            for (int i = 1; i < 10; i++) 
            { 
                dr = dt.NewRow(); 
                dr[0] = i; 
                dr[1] = "Person " + i; 
                dr[2] = "Company " + i; 
                dt.Rows.Add(dr); 
            } 
            
            DataColumn parentCol;
            parentCol = dt.Columns["Person_ID"]; 
            ds.Tables.Add(dt); 
            DataColumn[] PrimaryKeyColumns = new DataColumn[1]; 
            PrimaryKeyColumns[0] = dt.Columns["Person_Id"]; 
            dt.PrimaryKey = PrimaryKeyColumns; 
            Session["ds"] = ds; 
        } 
        else 
        { 
            ds = (DataSet)Session["ds"]; 
        } 
        
        return ds; 
    }
}

Open in new window

hmcgeehanAsked:
Who is Participating?
 
hmcgeehanConnect With a Mentor Author Commented:
thanks but i did it with this ...
protected void btnSaveClick(object sender, EventArgs e)
    {
        Button button1 = (Button)sender;

        TextBox tbName = (TextBox)button1.Parent.FindControl("tbName");

        if (tbName.Text == "")
        {
        }

    }

Open in new window

0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.