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


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.

<%@ 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" "">
<html xmlns="">
<head runat="server">
    <title>Untitled Page</title>
    <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:GridView ID="Grd" runat="server" AutoGenerateColumns="false" OnSelectedIndexChanged="Grd_SelectedIndexChanged">                
                        <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" />
                            <asp:TextBox ID="tbName" runat="server"></asp:TextBox>
                        <cc1:ModalPopupExtender ID="extPerson" runat="server" TargetControlID="lblPerson" PopupControlID="pnlPerson" DropShadow="true" CancelControlID="lnkClose" OkControlID="btnSave" />

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(); 



    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) {

    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; 
            DataColumn parentCol;
            parentCol = dt.Columns["Person_ID"]; 
            DataColumn[] PrimaryKeyColumns = new DataColumn[1]; 
            PrimaryKeyColumns[0] = dt.Columns["Person_Id"]; 
            dt.PrimaryKey = PrimaryKeyColumns; 
            Session["ds"] = ds; 
            ds = (DataSet)Session["ds"]; 
        return ds; 

Open in new window

Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

hmcgeehanAuthor 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


Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.