Click here to Skip to main content
15,920,030 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Greatings,

How I can open a web page from my website on the C# code, for example in a Onclick method of an button control, i used build web pages with JavaScript too Coldfusion with ActionScript. Javascript and ActionScript have "getURL()" function, and Coldfusion has "cflocation" tag:

Javascript and ActionScript:
getURL("Page1.html");


Coldfusion:

<cflocation url="Page1.cfm">


I have Visual Studio 2008
-------------------------------------------
I'm trying to navigate to a new webpage using a button click. I used RegisterClientScriptBlock method that Christian Graus suggest, Thanks very much, but the getURL() function not work:

protected void Button1_Click(object sender, EventArgs e)
    {
       ClientScriptManager myClientScriptManager = Page.ClientScript;
      myClientScriptManager.RegisterClientScriptBlock(this.GetType(),  "Script1", "getURL('Page1.aspx');", true);
    }


----------------------------------------

Upsss!! so sorry, yes getURL is from ActionScript and window.open from JavaScript, I was confused. Thanks Christian Graus, my code work so:

protected void Button1_Click(object sender, EventArgs e)
    {
       ClientScriptManager myClientScriptManager = Page.ClientScript;
      myClientScriptManager.RegisterClientScriptBlock(this.GetType(),  "Script1", "window.open('Page1.aspx', '_top');", true);
    }

Thanks Very much for your help:thumbsup::thumbsup::thumbsup:
Posted
Updated 26-Dec-09 4:41am
v6

wrote:
How I can open a web page from my website on the C# code,


I assume you're using ASP.NET ? Javascript and Actionscript run on the client machine. C# runs on the server. The only way to do this with C# is to inject javascript to do it into the page, using the RegisterClientScriptBlock method to add the script, presumably a call to window.open.
 
Share this answer
 
getURL does NOT open a new page in Javascript. window.open does that.
 
Share this answer
 
Yes, I use ASP .NET. BUt C# has and function similar?
 
Share this answer
 
"Yes, I use ASP .NET. BUt C# has and function similar?"

Um... I'm not sure how to better spell it out for you. C# runs on the SERVER, NOT on the client, therefore, any C# code that can be used to open a web page ( Process.Start will do it, if passed a URL ), would open a page on the SERVER, not the client. So, C# does have it, but it's not going to do what you want, for the reasons I stated.

If you don't understand that, you stand a chance of having all sorts of issues, I'd recommend buying an ASP.NET book and reading it.
 
Share this answer
 
Are you trying to programmatically download a webpage? Are you trying to open a webpage in a new window on a button click? Are you trying to navigate to a new webpage using the current window on a button click? Depending on what you want to do, you'll may need C#, JavaScript, HTML, ASP.Net, or a combination.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900