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

I have a list of Items on an Aspx Page and in order to edit each item I have launched SP.UI.ModalDialog

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

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1742411597a4438925.html

相关推荐

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

    I have a list of Items on an Aspx Page and in order to edit each item I have launched SP.UI.ModalDialog

    14小时前
    20

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信