flynny
asked on
ModalPopupExtender not working from code behind
Hi all,
I have a modalpopup extender which I want to use to show any errors which occur during some ajax transitions on a ASPX page.
Now I am testing and causing it to error (so the .cs code displayed is firing).
However, the modalpopup is not appearing? Am I doing somehting wron here?
I have a modalpopup extender which I want to use to show any errors which occur during some ajax transitions on a ASPX page.
Now I am testing and causing it to error (so the .cs code displayed is firing).
However, the modalpopup is not appearing? Am I doing somehting wron here?
<asp:ModalPopupExtender ID="ErrorModalPopupExtender" TargetControlID="btnDummy" PopupControlID="ModalPanel" runat="server" BackgroundCssClass="modal" DropShadow="true" />
<asp:Panel ID="ModalPanel" runat="server" BackColor="Aqua">
<asp:ErrorPopup ID="ErrorUserControl" runat="server" />
</asp:Panel>
<asp:Button ID="btnDummy" runat="server" Text="Button" style="display:none" />
ErrorUserControl.ErrorMessage = "Error trying to load " + controlPath;
ErrorUserControl.ErrorDump = ex.Message;
ErrorModalPopupExtender.Show();
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
The only thing that I see different in my code from yours beside the UpdatePanel is that my TargetControl button is within the panel (ModalPanel) for the pop-up and yours is not. Though I am not sure that would make a difference.
ASKER
Just tried adding it inside the ModalPanel and this has made no difference.
Any ideas?
Any ideas?
ASKER
I wonder whether or not it is because I am running the server code through AJAX and not initiating a full refresh of the page..
The user fills in a form (held in n ascx file).
The form is held inside an update panel. When the user submits the form, it inserts to the DB, sends an email and loads the next ascx page in the update panel.
Now because the page itself is not being refreshed, I thought it maybe because the page is not being refreshed. So I tried adding to the update panel itself.
however this does not work either?
The user fills in a form (held in n ascx file).
The form is held inside an update panel. When the user submits the form, it inserts to the DB, sends an email and loads the next ascx page in the update panel.
Now because the page itself is not being refreshed, I thought it maybe because the page is not being refreshed. So I tried adding to the update panel itself.
<asp:UpdatePanel ID="UpdatePanel1" runat="server">
<ContentTemplate>
<asp:PlaceHolder ID="PlaceHolderPageContent" runat="server"></asp:PlaceHolder>
<asp:Panel ID="ModalPanel" runat="server" BackColor="Aqua">
</asp:Panel>
</ContentTemplate>
</asp:UpdatePanel>
if (File.Exists(BASE_PATH + nextPage))
{
LastLoadedControl = BASE_PATH + nextPage;
LoadUserControl();
}
else
{
usercontrols_ErrorPopup ErrorUserControl = new usercontrols_ErrorPopup();
ErrorUserControl.ErrorMessage = "Error trying to load " + nextPage;
ModalPanel.Controls.Add(ErrorUserControl);
ModalPanel.Visible = true;
}
however this does not work either?
My user control does not have an UpdatePanel in it. I am doing something similar in mine. I have a pop-up user control where the user enters data and it loads into a database.
Are you loading the next control inside the previous one or the original page?
I would use the UpdatePanel on the main page and load / unload the controls within it, if that is possible.
Are you loading the next control inside the previous one or the original page?
I would use the UpdatePanel on the main page and load / unload the controls within it, if that is possible.
ASKER
Hi thanks for the reply.
In my .ASPX file I have my Update panel. I also have the modalpopup in the ASPX.
The update panel loads the relevent user control.
When a click of a button is detected I bubble the event back to the ASPX page to process.
So the click event is fired in the ASCX usercontrol, bubbles the event back (once all processes have ben completed) and passes the next usercontrol to load.
As this point if an error is detected I want to invoke the modalpopup which uses an error.ascx usercontrol to display the error.
In my .ASPX file I have my Update panel. I also have the modalpopup in the ASPX.
The update panel loads the relevent user control.
When a click of a button is detected I bubble the event back to the ASPX page to process.
So the click event is fired in the ASCX usercontrol, bubbles the event back (once all processes have ben completed) and passes the next usercontrol to load.
As this point if an error is detected I want to invoke the modalpopup which uses an error.ascx usercontrol to display the error.
I do not see anything that you are doing wrong. I am going to request attention on this question and see if we can get someone else involved that will see what we are missing.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Hi Alan,
First of all thank you for looking at this.
I think you were looking at the code which jmiller supplied, as the usercontrol is a simple text page.
Ok, One think with the modalpopupextender I can see (from firebug) is that the page will always present. As this is a Error popup I was hoping to only add this if an error were to be detected.
Therefore would it not make more sense to do the following (please tell me if i am wrong).
As the panel does not appear in the HTML at run time.
Then when the AJAX update is called do the following;
Which would load and appeand to the panel and then only add the usercontrol if needed.
However, I have tried this and the control doesnt appear?? As it is not a full postback (due to the fact it is an AJAX call) could this be the issue? If so how do I work around it?
First of all thank you for looking at this.
I think you were looking at the code which jmiller supplied, as the usercontrol is a simple text page.
Ok, One think with the modalpopupextender I can see (from firebug) is that the page will always present. As this is a Error popup I was hoping to only add this if an error were to be detected.
Therefore would it not make more sense to do the following (please tell me if i am wrong).
<asp:UpdatePanel ID="UpdatePanel1" runat="server">
<ContentTemplate>
<asp:PlaceHolder ID="PlaceHolderPageContent" runat="server"></asp:PlaceHolder>
<asp:Panel ID="ModalPanel" runat="server" BackColor="Aqua" Visible="false">
</asp:Panel>
</ContentTemplate>
</asp:UpdatePanel>
As the panel does not appear in the HTML at run time.
Then when the AJAX update is called do the following;
usercontrols_ErrorPopup ErrorUserControl = new usercontrols_ErrorPopup() { ErrorMessage = "Error trying to load " + nextPage };
ModalPanel.Controls.Add(ErrorUserControl);
ModalPanel.Visible = true;
ModalPanel.CssClass = "modal";
UpdatePanel1.Update();
Which would load and appeand to the panel and then only add the usercontrol if needed.
However, I have tried this and the control doesnt appear?? As it is not a full postback (due to the fact it is an AJAX call) could this be the issue? If so how do I work around it?
ASKER
Hi Guys,
I've located the problem. It was due tot he way I was loading the control to the panel. For completion heres the working code
its been a long day, sorry I should have seen this :)
I've located the problem. It was due tot he way I was loading the control to the panel. For completion heres the working code
usercontrols_ErrorPopup ErrorUserControl = (usercontrols_ErrorPopup)Page.LoadControl("~/usercontrols/ErrorPopup.ascx");
ErrorUserControl.ErrorMessage = "Error trying to load " + nextPage;
its been a long day, sorry I should have seen this :)
ASKER
Thanks for the help and responses guys.
ASKER
Thanks for the code.
The modalpopup isn't in an update panel.
However the click even i trigger the .show() from is bubbling an event from an ascx page.
I have breakpoint setup so the .show() is firing, its just that the popup is not appearing?
am I doing something wrong there?