Skip to content Skip to sidebar Skip to footer

Asp.net Button Type Link Should Open On New Window

using c# .net4.0 I am aware the asp.net button with in the gridview of type link does a post to the same page when clicked, i need make several manipualtion on server side before a

Solution 1:

you need to register script not response.write

so the code for you is :

ClientScript.RegisterStartupScript(this.GetType(), Guid.NewGuid().ToString(), "<scriptlanguage=JavaScript>window.open('http://www.google.co.uk','_blank')</script>");

Read more : ClientScriptManager.RegisterStartupScript.

Solution 2:

In a situation where I need to run server side code, before then opening a new page, I sometimes create a Generic Handler File and link to this with a HyperLink, passing variables as Query Strings. Therefore something like:

/MyGenericFile.ashx?id=123

In this file, I would have some scripting that needs to be carried out, followed by a Response.Redirect().

As long as the HyperLink is set to target="_blank", the user won't even know they've been to a generic file, which is then redirected. It will appear as they've opened a new link.

Therefore the process would be:

  • User clicks link to .ashx file
  • Link opens in new window
  • Necessary scripting is ran
  • Response.Redirect() is ran
  • User is taken to web page (www.google.com in your example)

I believe this same process is used by advert management systems to help track clicks.

Solution 3:

You can register a script to run on page load with ClientScriptManager.RegisterStartupScript.

Post a Comment for "Asp.net Button Type Link Should Open On New Window"