Linkbutton, Target="_blank"
-
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
-
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
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.
-
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.
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.
-
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
javascript:window.open('SampleDashboardDetails.aspx', ...)
is the only option to you. You have to do this from client side as Christian suggested. you can usethis.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.
-
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.
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.
-
javascript:window.open('SampleDashboardDetails.aspx', ...)
is the only option to you. You have to do this from client side as Christian suggested. you can usethis.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.
-
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. JMI 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.