locked
Ajax ModalPopupExtender from code behind does not set values RRS feed

  • Question

  • User800549252 posted

    I'm launching ModalPopupExtender from code behind (C#), where I want to set values in a Textbox and Label controls, but values are not set.

     Recreated my problem in a minimal webform app: 

    <%@ Page Title="eee" Language="C#" MasterPageFile="~/myMasterPage.Master" AutoEventWireup="true" CodeBehind="eee.aspx.cs" Inherits="myAJAX.eee" %>
    <%@ Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" TagPrefix="asp" %>
    <asp:Content ID="Content1" ContentPlaceHolderID="ContentPlaceHolder1" runat="server">
        <asp:Button ID="btnLaunchModal" runat="server" Text="Modal" OnClick="btnPopup_Click" />
        <asp:ModalPopupExtender ID="PopupModal" runat="server" TargetControlID="btnLaunchModal"
                                CancelControlID="btnClosePopup" PopupControlID="Panel1" BackgroundCssClass="myModalCss">
        </asp:ModalPopupExtender>
        <asp:Panel ID="Panel1" runat="server" BorderColor="Black" BorderStyle="Solid" 
                                              BorderWidth="1" BackColor="gray" Width="500px" Height="300px">
            Bla Bla Bla.....<br /><br />
            <asp:TextBox ID="TextBox1" runat="server" Text="AAA"></asp:TextBox><br /><br />
            <asp:Label ID="lblPopup" runat="server" Text="AAA"></asp:Label><br /><br />
            <asp:Button ID="btnClosePopup" runat="server" OnClick="btnPopup_Click" Text="Back" />
        </asp:Panel>
    </asp:Content>
    

    In my code behind :

            protected void btnPopup_Click(object sender, EventArgs e)
            {   TextBox1.Text = "BBB";
                lblPopup.Text = "BBB";
                PopupModal.Show();      }
    

    The initial values of the Textbox and the Label are AAA for both and are supposed to be changed to BBB before the panel pops up, but they don't.

    Where am I going wrong...?

    Thanks a lot!!!

    Gadi

    Sunday, August 23, 2015 12:47 PM

Answers

  • User-577741185 posted

    If you want to launch the modal from code-behind, you can't use that button as the TargetControlID; its server side click event won't be fired. Instead set the TargetControlID to a dummy / hidden button.

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Sunday, August 23, 2015 3:31 PM

All replies

  • User-577741185 posted

    If you want to launch the modal from code-behind, you can't use that button as the TargetControlID; its server side click event won't be fired. Instead set the TargetControlID to a dummy / hidden button.

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Sunday, August 23, 2015 3:31 PM
  • User800549252 posted

    YES!!!!  Thank you.

    Here's what I changed :

        .
        .
        <asp:HiddenField ID="HiddenField1" runat="server" />
        <asp:Button ID="btnLaunchModal" runat="server" Text="Modal" OnClick="btnPopup_Click" />
        <asp:ModalPopupExtender ID="PopupModal" runat="server" TargetControlID="HiddenField1"
            CancelControlID="btnClosePopup" DropShadow="true" PopupControlID="Panel1" BackgroundCssClass="myModalCss">
        </asp:ModalPopupExtender>
         .
         .
    

    Thanks again.

    Sunday, August 23, 2015 4:42 PM