最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Close SP.UI.ModalDialog PopUp from code behind - Stack Overflow

programmeradmin0浏览0评论

I have a list of Items on an Aspx Page and in order to edit each item I have launched SP.UI.ModalDialog popup to do so, a submit buton is created in this PopUp window to save changes and then close the pop up window :

protected void Submit_onclick(Object sender, EventArgs e)
{
    SPSecurity.RunWithElevatedPrivileges(delegate
    {
        try
        {
            using (SPSite mySite = new SPSite(PGContext.Site.ID))
            {
                using (SPWeb myweb = mySite.OpenWeb(PGContext.Web.ID))
                {
                    myweb.AllowUnsafeUpdates = true;
                    //changes
                    myweb.AllowUnsafeUpdates = false;

                    Page.ClientScript.RegisterStartupScript(this.GetType(), "closeWindow", "window.close()", true);}
                }
            }
            catch (Exception exp)
            {
                throw new Exception("ERROR: Unable to Save Changes : " + exp.Message.ToString(), exp);
            }
        });
}

but the Page.ClientScript.RegisterStartupScript() doesn't seem to work ! I've looked at it at msdn and it says that i can only use it on Page_Load() fonction , so how can I close my popup from the code in the event ?

I have a list of Items on an Aspx Page and in order to edit each item I have launched SP.UI.ModalDialog popup to do so, a submit buton is created in this PopUp window to save changes and then close the pop up window :

protected void Submit_onclick(Object sender, EventArgs e)
{
    SPSecurity.RunWithElevatedPrivileges(delegate
    {
        try
        {
            using (SPSite mySite = new SPSite(PGContext.Site.ID))
            {
                using (SPWeb myweb = mySite.OpenWeb(PGContext.Web.ID))
                {
                    myweb.AllowUnsafeUpdates = true;
                    //changes
                    myweb.AllowUnsafeUpdates = false;

                    Page.ClientScript.RegisterStartupScript(this.GetType(), "closeWindow", "window.close()", true);}
                }
            }
            catch (Exception exp)
            {
                throw new Exception("ERROR: Unable to Save Changes : " + exp.Message.ToString(), exp);
            }
        });
}

but the Page.ClientScript.RegisterStartupScript() doesn't seem to work ! I've looked at it at msdn and it says that i can only use it on Page_Load() fonction , so how can I close my popup from the code in the event ?

Share Improve this question asked Nov 23, 2012 at 9:53 Jojo GKHJojo GKH 573 silver badges7 bronze badges
Add a ment  | 

3 Answers 3

Reset to default 5

try this :

Response.Write("<script type='text/javascript'>window.frameElement.mitPopup();</script>");
Response.Flush();
Response.End();

try

this.Context.Response.Write("<script type='text/javascript'>parent.location.reload();</script>");

Thats what I used on my Code to close the Modal Dialog and also refresh the main page to display the updates made

The above code is working fine. It's working perfectly. But to refresh the parent page, use the below code which will work to close the popup and also show the loading message.

using (SPLongOperation operation = new SPLongOperation(this.Page)) {

   operation.Begin();

   //DO WORK HERE

   string redirectUrl = 'http://where-to-redirect-user-after';
     operation.End(redirectUrl, SPRedirectFlags.DoNotEncodeUrl, HttpContext.Current, null);
}
发布评论

评论列表(0)

  1. 暂无评论