C# RegisterStartupScript

  • In C#
  • Monday, February 01, 2016
  • 4290 Views

C# RegisterStartupScript

private void GrantAccessSuccess(string key, string urlReturn, string loginMode = "popup")
        {
            //string state = Request.QueryString["s"];
            if (Equals(loginMode, "popup"))
            {
                if (!Page.ClientScript.IsStartupScriptRegistered(GetType(), key))
                    // do something
                {
                    Logger.Info("Login success not IsStartupScriptRegistered");
                    Page.ClientScript.RegisterStartupScript(GetType(), key,
                                                            string.Format(
                                                                "<script type='text/javascript'>if(typeof parent.jQuery!='undefined' && typeof parent.jQuery.fancybox!='undefined') parent.jQuery.fancybox.close();parent.document.location = '{0}';</script>",
                                                                urlReturn));
                }

                else
                {
                    Logger.Info("Login success IsStartupScriptRegistered");
                    Response.Redirect(urlReturn);
                }

               /* try
                {
                    const string l = "{";
                    const string r = "}";
                    if (!Page.ClientScript.IsStartupScriptRegistered(GetType(), key))
                        // do something
                        Page.ClientScript.RegisterStartupScript(GetType(), key,
                                                                string.Format("<script type='text/javascript'>try{1} if(self.opener!=null) self.opener.document.location = '{0}'; else document.location = '{0}';window.close();{2} catch(e){1}document.location = '{0};'{2}</script>",
                                                                urlReturn, l, r));
                    else Response.Redirect(urlReturn);
                }
                catch (Exception e)
                {
                    Logger.Error(e);
                    Response.Redirect(urlReturn);
                }*/
            }
            else
            {
                Logger.Info("Login success not popup");
                //if (!string.IsNullOrEmpty(state))
                //{
                //    urlReturn = string.Format("{0}{1}s={2}", urlReturn, urlReturn.IndexOf('?') > 0 ? "&" : "?", state);              
                //}

                Response.Redirect(urlReturn, false);
            }

        }