Question : Showing ModalPop-Up from Code Behind Not Working

Hi there,

I'm trying to show a modalpop-up from code behind.

The pop-up contains a label that I update after a button click, after it's been updated I want it to be shown to the user.

It seems to me that the $find(ModalClientID); isn't able to find the modal popup that is on the page, even though Im passing it the mdlPopUpExt.BehaviorID in the code behind.

Not sure where the problem is in my code.
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
//Javascript function to show modalpopup
<script type="text/javascript" language="javascript">
        function ShowModalErrors(ModalClientID) {
            var modalPopUp = $find(ModalClientID);
            if (modalPopUp != null) { modalPopUp.show(); }
            return false;
        }
</script>

//ASPX Page Controls
<asp:Panel ID="pnlPopUp" runat="server" Visible="false" CssClass="modalPopup">
<asp:UpdatePanel ID="updErrors" runat="server" UpdateMode="Conditional">
<ContentTemplate>
    <asp:Label ID="lblPopUp" CssClass="Label" runat="server" /><br /><br />
    <asp:Button ID="btnOk" runat="server" Text="OK" />
</ContentTemplate>
<Triggers>
    <asp:AsyncPostBackTrigger ControlID="btnSave" EventName="Click" />
</Triggers>
</asp:UpdatePanel>
</asp:Panel>
<AJAXToolKit:ModalPopupExtender ID="mdlPopUpExt" BehaviorID="mdlPopUpExtID" 
    TargetControlID="lblInputErrors"
    PopupControlID="pnlPopUp"
    DropShadow="false" 
    BackgroundCssClass="modalBackground"
    OkControlID="btnOk"
    runat="server" />
<asp:Label ID="lblInputErrors" visible="false" runat="server" />
...
<asp:LinkButton ID="btnSave" Font-Underline="True" CssClass="LabelButton" Text="Save Pricing" 
Runat="server" OnClick="btnSave_Click" ToolTip="Save Pricing" />

//ASPX Page Code Behind
protected void btnSave_Click(object sender, EventArgs e)
{
     ...
     lblPopUp.Text = "Some Random text";
     //TODO: Figure out why it can't find the modal popup extender id
     ScriptManager.RegisterStartupScript(this, this.GetType(), "Data_Errors", "ShowModalErrors('" + mdlPopUpExt.BehaviorID + "');", true);
}

Answer : Showing ModalPop-Up from Code Behind Not Working

Stupid I didn't saw it earlier. You are saying that your panel is not visible, the modalpopupextender doesn't set your panel to visible, only setting it to "display: block" try the following example instead



<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Default.aspx.cs" Inherits="WebApplication1._Default" %>
<%@ Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" TagPrefix="ajax" %>
<!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">
    <title></title>
</head>
<body>
    <form id="form1" runat="server">
    <asp:ScriptManager ID="ScriptManager1" runat="server">
    </asp:ScriptManager>
    <div>
    <asp:UpdatePanel ID="upSend" runat="server">
        <ContentTemplate>
            <asp:Button ID="btnSend" runat="server" text="Button" OnClick="btnSend_Click" />
           
           
           
        </ContentTemplate>
    </asp:UpdatePanel>
    <asp:Panel ID="pnlShow" runat="server" style="display: none">
                <h1>hello world</h1>
            </asp:Panel>
            <asp:HiddenField ID="hd_dyn" runat="server" />
    <ajax:ModalPopupExtender ID="mdlhelloWorld" TargetControlID="hd_dyn" PopupControlID="pnlShow" runat="server" />
    </div>
    </form>
</body>
</html>


protected void btnSend_Click(object sender, EventArgs e)
        {
            mdlhelloWorld.Show();
        }



as you can see, i've added " style="display: none" " to the panel.
Random Solutions  
 
programming4us programming4us