Pop-up Child Window

1

I have the following button that basically inserts data from a web form, but this button is in a pop-up child . What I intend is that when I run the button, after inserting the data close the pop-up window.

How do I solve this problem?

protected void Criar_Fornecedor_Click(object sender, EventArgs e)
{
    if (Page.IsValid)
    {
        try
        {
            AddItemToListFornecedores(SPContext.Current.Web.CurrentUser);
            string tempurl = currentsiteurl + "/Lists/EntidadesFornecedores/AllItems.aspx";
            SPUtility.Redirect(tempurl, SPRedirectFlags.DoNotEndResponse, HttpContext.Current);
        }
        catch (Exception ex)
        {
            throw new SPException(ex.Message);
        }
    }
}
    
asked by anonymous 12.06.2014 / 00:39

2 answers

1

If you are using ModalPopupExtender, you can close it by code-behind with the following call: ModalPopupExtenderID.Hide(); , in your Criar_Fornecedor_Click method. Soon, it would look like this:

protected void Criar_Fornecedor_Click(object sender, EventArgs e)
{
    if (Page.IsValid)
    {
       try
        {
            AddItemToListFornecedores(SPContext.Current.Web.CurrentUser);
            string tempurl = currentsiteurl + "/Lists/EntidadesFornecedores/AllItems.aspx";
            SPUtility.Redirect(tempurl, SPRedirectFlags.DoNotEndResponse, HttpContext.Current);
            // fecha modal, através do ModalPopupExtender, que se chama ModalPopupExtenderID
            ModalPopupExtenderID.Hide();
        }
        catch (Exception ex)
        {
            throw new SPException(ex.Message);
        }
    } 
}

If you have it open via javascript, you can register the execution of a script that closes its modal:

ScriptManager.RegisterStartupScript(this, typeof(Page), "CloseModal", "$(document).ready(function(){closeModal();});", true);

You need a javscript called closeModal(); , already existing, that closes its modal:

<script> 
    function coloseModal() {
       // fecha o seu modal - no exemplo a seguir ele é um dialog do jquery        
       $( "#IdDoModal" ).dialog("close");
    }
</script>
    
12.07.2014 / 23:20
0

Thank you very much to everyone, but I solved this. in my save button, it runs the function "AddItemToListFórecedores" and in the end it redirects to another page

Record Code:

        protected void Criar_Fornecedor_Click(object sender, EventArgs e)
    {

        if (Page.IsValid)
        {
            try
            {
                // alterar o link para a listagem correspondente no sharepoint
                AddItemToListFornecedores(SPContext.Current.Web.CurrentUser);
                string tempurl = currentsiteurl + "/Lists/EntidadesFornecedores/AllItems.aspx";
                Response.Redirect("./ConfirmaFornecedor.aspx?IsDlg=1");


            }
            catch (Exception ex)
            {
                Response.Redirect("./ConfirmaFornecedor.aspx?IsDlg=1");
            }
            finally
            {
                ClientScript.RegisterStartupScript(typeof(Page), "closePage", "window.close();", true);
            }

        }

    }

Second page code to close Pop-up: .ASPX

<asp:Content ID="Main" ContentPlaceHolderID="PlaceHolderMain" runat="server">
<script type="text/javascript">


    function finisheDialog() {
        SP.UI.ModalDialog.commonModalDialogClose(SP.UI.DialogResult.OK, 'Cancelled clicked');
    }


</script>

<div>
    <table>
        <tr>
            <td>
                Registo Efectuado com sucesso. Clicar em sair para regressar á página.
            </td>

        </tr>
        <tr>
            <td style="text-align: center">&nbsp;</td>

        </tr>
        <tr>
            <td style="text-align: center">
            <input type="button" runat="server" id="btnCancel" value="Fechar"  /></td>

        </tr>
    </table>
</div>

.CS code

        protected void Page_Load(object sender, EventArgs e)
    {
        btnCancel.Attributes["onclick"] = "finisheDialog()";
    }
    
14.07.2014 / 19:31