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" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<style type="text/css">

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

   </style>

 
    <title></title>
</head>
<body>
    <form id="form1" runat="server">
        <asp:ScriptManager ID="ScriptManager1" runat="server"> 
    </asp:ScriptManager>

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

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

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

    </asp:Panel>


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

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

        </asp:GridView>

             <asp:Button ID="btnPickrecord" runat="server" Text="Pick Record" 
             onclick="btnPickrecord_Click "   />
    <asp:Button ID="btnload" runat="server" onclick="btnload_Click"  
        Text="Load Data" />
                </ContentTemplate>
     </asp:UpdatePanel>
     
        </div>
        <asp:Button ID="btnCancel" runat="server" Text="Close Me" 
                 onclick="btnCancel_Click" />
    </asp:Panel>
        <asp:TextBox ID="txtreference" runat="server" AutoPostBack="True"></asp:TextBox>
        <p>
            &nbsp;</p>
    </form>
</body>
</html>

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";

            this.Panel1.Controls.Add(modalPop); 

            modalPop.Show();
        }

Thanks

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.