I need help on a section of the code below to revise so instead of redirect to a full page I want it to redirect and open as a popup window. How can i change the code I have to make this possible.

void context_AcessDenied(object sender, EventArgs e)
        {
            try
            {
                HttpApplication httpApp = sender as HttpApplication;
                HttpContext context = httpApp.Context;

                string httpUrl = context.Request.Url.ToString();   
                string strSiteURL = string.Empty;
                string strWebURL = string.Empty;
                string strOwnerName = string.Empty;
                string strOwnerEmail = string.Empty;

                if (httpUrl.ToLower().Contains("/_layouts/accessdenied.aspx") && !httpUrl.ToLower().Contains("loginasanotheruser=true"))
                {
                    strSiteURL = SPContext.Current.Web.Url;

                    SPSecurity.RunWithElevatedPrivileges(delegate()
                    {
                        using (SPSite site = new SPSite(strSiteURL))
                        {
                            using (SPWeb web = site.OpenWeb())
                            {
                                strWebURL = web.Url;
                                SPGroupCollection groups = web.Groups;

                                foreach (SPGroup group in groups)
                                {
                                    if (group.Name.ToLower().Contains("owner") && !group.Name.ToLower().Contains("sub-owner") && group.Users.Count > 0)
                                    {
                                        SPUser owner = group.Users[0];
                                        strOwnerName = owner.Name;
                                        strOwnerEmail = owner.Email;
                                    }
                                }
                            }
                        }
                    });

                    HttpContext.Current.Server.ClearError();
                    HttpContext.Current.Response.Clear();
                    //strCustomAcssDndURL = getAppSettingsValue(m_SiteCollCustAcsDndPG + "-" + strSiteURL);
                    //HttpContext.Current.Response.Redirect(strCustomAcssDndURL, false);

                    string redirect = getAppSettingsValue(m_SiteCollCustAcsDndPG);
                    redirect += "?ReqURL=" + strWebURL;

                    if (!string.IsNullOrEmpty(strOwnerEmail))
                        redirect += "&OwnEmail=" + strOwnerEmail;

                    if(!string.IsNullOrEmpty(strOwnerName))
                        redirect += "&OwnName=" + strOwnerName;

                    HttpContext.Current.Response.Redirect(redirect, false);                    
                }
            }
            catch (Exception ex)
            {
                //Do your exception handling

                HttpContext.Current.Server.ClearError();
                HttpContext.Current.Response.Clear();
                HttpContext.Current.Response.Redirect("/Pages/AccessDeniedOverride.aspx?Error=true&Message=" + ex.Message);
            }
        }

Try the following code

string url="http://www.google.com";
Response.Write("<script>window.open('" +url+ "');</script>");

I have just find out the following code check this too. You need to add the following to your server side link/button:

OnClientClick="aspnetForm.target ='_blank';"

The entire button code will look something like:

<asp:LinkButton ID="myButton" runat="server" Text="Click Me!" OnClick="myButton_Click" OnClientClick="aspnetForm.target ='_blank';"/>

Hi,
You can try this as well,

In the code behind where you perform the redirect operation, instead try something like this,

Dim jsStr As String = "window.open('" +url+ "');"
ScriptManager.RegisterStartupScript(Me.Page, Me.Page.GetType(), "", jsStr, True)

Try the following code

string url="http://www.google.com";
Response.Write("<script>window.open('" +url+ "');</script>");

Just trying to see how I could apply this code to my code:

I updated this:

redirect += "?ReqURL=" + strWebURL;

to this this:

string redirect = getAppSettingsValue(m_SiteCollCustAcsDndPG);
                    [B]redirect += ("<script>window.open?ReqURL=" + strWebURL + ");</script>");[/B]

                    if (!string.IsNullOrEmpty(strOwnerEmail))
                        redirect += "&OwnEmail=" + strOwnerEmail;

                    if(!string.IsNullOrEmpty(strOwnerName))
                        redirect += "&OwnName=" + strOwnerName;

                    HttpContext.Current.Response.Redirect(redirect, false);                    
                }
            }
            catch (Exception ex)
            {
                //Do your exception handling

                HttpContext.Current.Server.ClearError();
                HttpContext.Current.Response.Clear();

                string url = "/Pages/AccessDeniedOverride.aspx";
             HttpContext.Current.Response.Write("<script>window.open('" + url + "');</script>");
               
                HttpContext.Current.Response.Redirect("/Pages/AccessDeniedOverride.aspx?Error=true&Message=" + ex.Message);
            }

Does this look correct. I can't tell whether I need to update the HttpContext redirect line or the redirect + line.

Anyone with any ideas on this please.

where you want you use pop-up use response.write instead of redirect

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.