Pop-up Child window

Asked

Viewed 1,246 times

2

I have the following button that basically inserts data from a web form, but that button is on a pop-up. What I intend is that when you run the button, after entering the data close the window of the pop-up.

How to 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);
        }
    }
}

2 answers

1

If you are using Modalpopupextender, you can close it by code-Behind via the following call: ModalPopupExtenderID.Hide();, in his method Criar_Fornecedor_Click. Soon he’d be 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 opened it via javascript, you can register the execution of a script that closes your modal:

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

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

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

0

Thank you all very much, but I took care of it. on my record button, runs the function "Additemtolistfornecedores" and in the end redirects to another paginja

Code Record:

        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);
            }

        }

    }

Code of the second page to close the 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>

Code . CS

        protected void Page_Load(object sender, EventArgs e)
    {
        btnCancel.Attributes["onclick"] = "finisheDialog()";
    }
  • If your problem has been solved, mark your answer as correct.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.