Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Web Development
  3. ASP.NET
  4. Linkbutton, Target="_blank"

Linkbutton, Target="_blank"

Scheduled Pinned Locked Moved ASP.NET
csharptutorial
7 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • J Offline
    J Offline
    JohnQuar1
    wrote on last edited by
    #1

    Hello, I have a couple of link buttons and I am trying to get them to open a page in a new window. I know how to do this with a normal link, but I also have some very simple code behind that I need to run (Set a session variable). I am writing this in C#, and have had no luck getting the page to open with the session variable passed. Let me know if you have any suggestions, or if you know how to do this through a normal link. Thanks for your time. C# Code

    protected void lnkEnterprise_Click(object sender, EventArgs e)
    {
    Session["Owner"] = 1;
    Response.Redirect("~/SampleDashboardDetails.aspx");
    }

    JM

    C A 2 Replies Last reply
    0
    • J JohnQuar1

      Hello, I have a couple of link buttons and I am trying to get them to open a page in a new window. I know how to do this with a normal link, but I also have some very simple code behind that I need to run (Set a session variable). I am writing this in C#, and have had no luck getting the page to open with the session variable passed. Let me know if you have any suggestions, or if you know how to do this through a normal link. Thanks for your time. C# Code

      protected void lnkEnterprise_Click(object sender, EventArgs e)
      {
      Session["Owner"] = 1;
      Response.Redirect("~/SampleDashboardDetails.aspx");
      }

      JM

      C Offline
      C Offline
      Christian Graus
      wrote on last edited by
      #2

      JohnQuar1 wrote:

      Response.Redirect("~/SampleDashboardDetails.aspx");

      Well, this is your problem. Obviously, given how ASP.NET works, redirecting in your C# code can never open a new window, that's just impossible. You need to open a new window in your client side code.

      Christian Graus Driven to the arms of OSX by Vista. Read my blog to find out how I've worked around bugs in Microsoft tools and frameworks.

      J 1 Reply Last reply
      0
      • C Christian Graus

        JohnQuar1 wrote:

        Response.Redirect("~/SampleDashboardDetails.aspx");

        Well, this is your problem. Obviously, given how ASP.NET works, redirecting in your C# code can never open a new window, that's just impossible. You need to open a new window in your client side code.

        Christian Graus Driven to the arms of OSX by Vista. Read my blog to find out how I've worked around bugs in Microsoft tools and frameworks.

        J Offline
        J Offline
        JohnQuar1
        wrote on last edited by
        #3

        I agree with you, and I would write some small javascript to do this, but I need to pass that session variable as well. The page I am trying to open has a gridview that has a session variable parameter as an input, so I need to pass the session before the page loads so that the gridview is immediately populated.

        A 1 Reply Last reply
        0
        • J JohnQuar1

          Hello, I have a couple of link buttons and I am trying to get them to open a page in a new window. I know how to do this with a normal link, but I also have some very simple code behind that I need to run (Set a session variable). I am writing this in C#, and have had no luck getting the page to open with the session variable passed. Let me know if you have any suggestions, or if you know how to do this through a normal link. Thanks for your time. C# Code

          protected void lnkEnterprise_Click(object sender, EventArgs e)
          {
          Session["Owner"] = 1;
          Response.Redirect("~/SampleDashboardDetails.aspx");
          }

          JM

          A Offline
          A Offline
          Abhishek Sur
          wrote on last edited by
          #4

          javascript:window.open('SampleDashboardDetails.aspx', ...) is the only option to you. You have to do this from client side as Christian suggested. you can use this.ClientScript.RegisterStartupScript(this.GetType(), "aa", "window.open(...);", true); to write the script response to the client. :)

          Abhishek Sur


          My Latest Articles **Create CLR objects in SQL Server 2005 C# Uncommon Keywords Read/Write Excel using OleDB

          **Don't forget to click "Good Answer" if you like to.

          J 1 Reply Last reply
          0
          • J JohnQuar1

            I agree with you, and I would write some small javascript to do this, but I need to pass that session variable as well. The page I am trying to open has a gridview that has a session variable parameter as an input, so I need to pass the session before the page loads so that the gridview is immediately populated.

            A Offline
            A Offline
            Abhishek Sur
            wrote on last edited by
            #5

            how about using

            this.ClientScript.RegisterStartupScript(this.GetType(), "aa", "window.open(\"yourpage.aspx?s=" + Session["val"].ToString() + "\");", true);

            means passing through querystring?

            Abhishek Sur


            My Latest Articles **Create CLR objects in SQL Server 2005 C# Uncommon Keywords Read/Write Excel using OleDB

            **Don't forget to click "Good Answer" if you like to.

            1 Reply Last reply
            0
            • A Abhishek Sur

              javascript:window.open('SampleDashboardDetails.aspx', ...) is the only option to you. You have to do this from client side as Christian suggested. you can use this.ClientScript.RegisterStartupScript(this.GetType(), "aa", "window.open(...);", true); to write the script response to the client. :)

              Abhishek Sur


              My Latest Articles **Create CLR objects in SQL Server 2005 C# Uncommon Keywords Read/Write Excel using OleDB

              **Don't forget to click "Good Answer" if you like to.

              J Offline
              J Offline
              JohnQuar1
              wrote on last edited by
              #6

              So I'm a little confused, does this.ClientScript.RegisterStartupScript(this.GetType(), "aa", "window.open(\"~/SampleDashboardDetails.aspx?s=" + Session["Owner"].ToString() + "\");", true); go on the page I am trying to open in the page load? Thanks. JM

              J 1 Reply Last reply
              0
              • J JohnQuar1

                So I'm a little confused, does this.ClientScript.RegisterStartupScript(this.GetType(), "aa", "window.open(\"~/SampleDashboardDetails.aspx?s=" + Session["Owner"].ToString() + "\");", true); go on the page I am trying to open in the page load? Thanks. JM

                J Offline
                J Offline
                JohnQuar1
                wrote on last edited by
                #7

                I found a solution. I ended up changing the link buttons to links and passed a variable through the link, then grabbed the variable and stored it to the session variable I was using in a Page_PreInit function. Send it from first page: Receive on second page:

                protected void Page_PreInit(Object sender, EventArgs e)
                {
                Session["Owner"] = Request.QueryString["Owner"];
                }

                Thanks for your help guys.

                1 Reply Last reply
                0
                Reply
                • Reply as topic
                Log in to reply
                • Oldest to Newest
                • Newest to Oldest
                • Most Votes


                • Login

                • Don't have an account? Register

                • Login or register to search.
                • First post
                  Last post
                0
                • Categories
                • Recent
                • Tags
                • Popular
                • World
                • Users
                • Groups