vuyiswamb 17 Posting Whiz

I see a lot of people have been asking this question, some was because of the if postback check , but mine is different. i am using AjaxModalExtender to show my popup on the server side. this is my markup

<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="TestPage.aspx.cs" Inherits="PopTester.TestPage" %>

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

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "">

<html xmlns="">
<head runat="server">
<style type="text/css">

{     background-color: Yellow;
      filter: alpha(opacity=60);
      opacity: 0.6;


    <form id="form1" runat="server">
        <asp:ScriptManager ID="ScriptManager1" runat="server"> 

    <asp:Panel ID="Panel1" runat="server">

    <asp:Button ID="Button1" runat="server"

    Text="CreateModal" OnClick="Button1_Click" />


         <asp:Panel ID="ModalPanel" runat="server" Style="display: none" HorizontalAlign="Center" BackColor="Green">
     <asp:UpdatePanel ID="Update" runat="server">
        <asp:GridView ID="GridView1"  AutoGenerateColumns="false" runat="server" Height="176px" Width="453px">
        <asp:TemplateField HeaderText="ID">
        <asp:CheckBox ID="chkId" runat="server" />
        <asp:Label ID="lblId" runat="server" Text='<%#Eval("ID")%>'></asp:Label>
        <asp:TemplateField HeaderText="Name">
        <asp:Label ID="lblname" runat="server" Text='<%#Eval("Name") %>'></asp:Label>

        <asp:TemplateField HeaderText="Lastname">
        <asp:Label ID="lblLastname" runat="server" Text='<%#Eval("Lastname") %>'></asp:Label>


             <asp:Button ID="btnPickrecord" runat="server" Text="Pick Record" 
             onclick="btnPickrecord_Click "   />
    <asp:Button ID="btnload" runat="server" onclick="btnload_Click"  
        Text="Load Data" />
        <asp:Button ID="btnCancel" runat="server" Text="Close Me" 
                 onclick="btnCancel_Click" />
        <asp:TextBox ID="txtreference" runat="server" AutoPostBack="True"></asp:TextBox>

as you can see i have a gridview that will be on the modal and its working fine, now after the grid has returned some results, i will select one record via the checkbox on the Grid and click the button "btnPickrecord" and this will fire my server side code

protected void btnPickrecord_Click(object sender, EventArgs e)
                 foreach (GridViewRow dataItem in GridView1.Rows)

                    CheckBox chkselect = (CheckBox)dataItem.FindControl("chkId");
                    if (dataItem.RowType == DataControlRowType.DataRow)
                          if (chkselect.Checked)
                              Label lblReferenceNumberID = (Label)dataItem.FindControl("lblId");

                              txtreference.Text = lblReferenceNumberID.Text;

the breakpoints got a hit and i stepped through it and i the value get assigned to the textbox <b> txtreference.Text</b> , but when i close the modal the textbox is empty , or while the modal is open i can see the value does not reflect in the parent page. Here is the Code for invoking the modal

protected void Button1_Click(object sender, EventArgs e)
            AjaxControlToolkit.ModalPopupExtender modalPop = new AjaxControlToolkit.ModalPopupExtender();

            modalPop.ID = "popUp";

            modalPop.PopupControlID = "ModalPanel";

            modalPop.TargetControlID = "Button1";

            modalPop.DropShadow = true;

            modalPop.BackgroundCssClass = "modalBackground";

            modalPop.CancelControlID = "btnCancel";