Open new window with Response.Redirect() in 3rd part

In 2nd part of the following post I show you how to open a new window in using "ResponseHelper "class. Now today I want to share another approach with "Extension method".

Third approach(Extension method)
public static class ResponseHelper {
    public static void Redirect(this HttpResponse response,
        string url,
        string target,
        string windowFeatures) {
        if ((String.IsNullOrEmpty(target) ||
.OrdinalIgnoreCase)) &&
                         String.IsNullOrEmpty(windowFeatures)) {
        else {
            Page page = (Page)HttpContext.Current.Handler;
            if (page == null) {
                throw new InvalidOperationException(
                    "Cannot redirect to new window outside
Page context."
            url = page.ResolveClientUrl(url);
            string script;
            if (!String.IsNullOrEmpty(windowFeatures)) {
                script = @"""{0}"", ""{1}"",
            else {
                script = @"""{0}"", ""{1}"");";
            script = String.Format(script, url, target,

Note the 'this' keyword in the first parameter.
Now whenever we include the namespace this class
is defined within, we get a nice override on the
actual Response object.

Response.Redirect("popup.aspx", "_blank", "menubar=0,width=100,height=100");


Popular posts from this blog

The model backing the 'MyDBContext' context has changed since the database was created. Either manually delete/update the database, or call Database.SetInitializer with an IDatabaseInitializer instance. For example, the DropCreateDatabaseIfModelChanges strategy will automatically delete and recreate the database, and optionally seed it with new data.

"This request has been blocked because sensitive information could be disclosed to third party web sites when this is used in a GET request. To allow GET requests, set JsonRequestBehavior to AllowGet."

Check/Uncheck all items in a CheckBoxList using Javascript