Two pages are named: Abc.aspx and popupAbc.aspx
On the Abc.aspx page, there is a button that opens popupAbc.aspx as a pop-up:
<asp:Button ID="btnOpenChildAbcPopup" runat="server" Text="Open" UseSubmitBehavior="false" CausesValidation="False" OnClick="btnOpenChildAbcPopup_Click" />
Code Behind:
protected void btnOpenChildAbcPopup_Click(object sender, EventArgs e)
{
string url="../popupAbc.aspx";
ScriptManager.RegisterStartupScript(Page, GetType(), "alert", "OpenChildAbcPopup('" + url + "');",
true);
}
function OpenChildAbcPopup(url) {
$.fancybox({
'onStart ': function () { $.fancybox.hideActivit() },
'onComplete': function () { $.fancybox.hideActivity() },
'titleShow': 'true',
'titlePosition': 'over',
'titleFormat': 'formatTitle',
'href': url,
'type': 'iframe',
'width': '1000',
'height': '500',
'fitToView': false,
'autoSize': false,
'hideOnOverlayClick': false,
'hideOnContentClick': false,
'overlayOpacity': 0.7,
'enableEscapeButton': false,
'closeEffect': 'none'
});
$.fancybox.hideLoading();
return false;
}
Everything works perfectly up to this point. However, there is an issue within the popupAbc.aspx
.
In the popupAbc.aspx
page, there is a save button that, upon clicking, should call a JavaScript function on the master page, but it is not working.
This code is in the popupAbc.aspx page:
<%@ Page Language="C#" AutoEventWireup="true" MasterPageFile="~/MyMaster.Master" CodeBehind="popupAbc.aspx.cs" Inherits="popupAbc.aspx" %>
<asp:Button ID="btnSubmit" runat="server" Text="Save" OnClick="btnSubmit_Click" UseSubmitBehavior="true" ValidationGroup="p1" />
protected void btnSubmit_Click(object sender, EventArgs e)
{
// Save form data in database and then call a JavaScript function on the MyMaster page
ScriptManager.RegisterStartupScript(Page, GetType(), "Js", "ExitMyCurrentFancyBox();", true);
}
An error is thrown in the console saying that ExitMyCurrentFancyBox is not defined.
When the ExitMyCurrentFancyBox function is moved to the popupAbc.aspx
, it successfully calls. However, when placed on the master page, it does not work.
function ExitMyCurrentFancyBox() {
alert()
}
Note:The Abc.aspx page uses an update panel, while popupAbc.aspx does not use one.
Any suggestions on why the JavaScript function is not calling when placed on the master page and how to make it work?
I have tried various methods, but none of them seem to be effective:
// ScriptManager.RegisterStartupScript(Page, GetType(), "alert", "ExitMyCurrentFancyBox();", true);
// ScriptManager.RegisterStartupScript(Page, GetType(), "alert", "ExitMyCurrentFancyBox();", true);
//ClientScript.RegisterClientScriptBlock(GetType(), "sas", "CloseFancyboxtl();", true);
// ScriptManager.RegisterStartupScript(this, this.GetType(), "ntmtch", "ExitMyCurrentFancyBox();", true);
// ScriptManager.RegisterStartupScript(Page, Page.GetType(), "msg", "ExitMyCurrentFancyBox();", true);
//ScriptManager.RegisterStartupScript(this, this.GetType(), "msg", "ExitMyCurrentFancyBox;", true);
ScriptManager.RegisterClientScriptBlock(this.Page, GetType(), Guid.NewGuid().ToString(), "ExitMyCurrentFancyBox();", true);