0

I have an ASP.NET button in my application, which I want to open another website on my server in a new window. Currently I do a Response.Redirect in my server side on click event (to "..\OtherWebsite") which works. But as it needs to be in a new window I need to do it in JavaScript.

Would '..\OtherWebsite' path work in the window.open JavaScript command? If not, what .NET methods/properties can I use to get the full path?

I can't hard code the website URL as some users will be accessing through a LAN (server name\application) and some through the website (www.website.com/application)

Msonic
  • 1,456
  • 15
  • 25
Chris
  • 7,415
  • 21
  • 98
  • 190

2 Answers2

1

You can use self.location.href to get the currect url of the page, next form your new url relative to that and then pass it to window.open() method.

Here is the definition of window.open method.

Hope this helps...

Kaf
  • 33,101
  • 7
  • 58
  • 78
1

You can do this by executing the javascript from the codebehind.

public void OpenNewWindow(string url)
{

   ClientScript.RegisterStartupScript(this.GetType(), "newWindow", String.Format("<script>window.open('{0}');</script>", url));
}

http://forums.asp.net/t/1001747.aspx/1

First result from searching for "open new window from codebehind c# .net"

Then just pass the relative url like so.

String url = "~/page.aspx";
url = Page.ResolveClientUrl(url);
OpenNewWindow(url);

also a reference here: Response.Redirect to new window

Hope this helps.

Community
  • 1
  • 1
Brandon
  • 339
  • 3
  • 11