简体   繁体   中英

Hide the ASPxPopupControl from code behind

I have added an ASPxPopupControl, which includes a Save Button, and I want to close it after saving a record.

I tried the following:

 string str = @"<script language=""javascript"" type=""text/javascript"">function HideEscalateAsk() {pcEscalteAsk.Hide();}</script>";
                   Page.RegisterClientScriptBlock("ClientScript", str);

but it still doesn't work. How can I close the ASPxPopupControl?

First thing. How are you handling Save Button; Server Side event or Client Side .

If you are using client side then use Callback server side event to save data and End Callback client event to close popup.

If using Server Side event then use ASPxPopupControl.ShowOnPageLoad Property.

protected void btnShowPopup_Click(object sender, EventArgs e) {
            txtPopup.Text = txtMain.Text;
            ASPxPopupControl1.ShowOnPageLoad = true;
        }
        protected void btnOK_Click(object sender, EventArgs e) {
            // TODO: your code is here to process the popup window's data at the server
            txtMain.Text = txtPopup.Text;
            ASPxPopupControl1.ShowOnPageLoad = false;
        }

Refer following links for information:
How to show the ASPxPopupControl
How to show and hide a popup window via server side code

I think this is the best way for that as DevSupport mentioned. You must be write a java script like below:

//This function will close the pop window
function ClosePopWindow() {
     var paentWin = window.parent;
     window.parent.PopWindow.Hide();
}

And

//This function will clear inside content of pop window
function ClearPopWindow() {
        var paentWin = window.parent;
        paentWin.PopWindow.SetContentHtml(null);            
   }

and then call it from code behind when you need (after all of process you want to do) like this:

Page.ClientScript.RegisterStartupScript(GetType(), "script", "ClosePopWindow();", true);

or if you want to clear content you can use second function. Attention the PopWindow is ClientInstanceName of ASPxPopupControl . This approach will work in any situation for example when pop window defined in Master page and content URL is a window without master page because it try to get parent window in final html elements in browser.

You can read a Dev Support answer at this: https://www.devexpress.com/Support/Center/Question/Details/B199294

And from ASP.NET Forums, Terry Guo answer at this: http://forums.asp.net/t/1990775.aspx?How+to+close+the+popup+from+the+popup+containing+page+

Hope this help.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM