Jump to content
  • Advertisement
Sign in to follow this  
ThunderSoul

[.net] ASP.NET Buttons and Navigation

This topic is 3664 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi, I created a button in ASP.NET and I would like to know how I can use it to navigate to, say, www.yahoo.com if I click it, as I would click an html link. Please help, thank you!

Share this post


Link to post
Share on other sites
Advertisement
System.Diagnostics.Process.Start("http://www.website.com") will open the default program for the file type (the default browser) and display the link. To put it in a button, you would add the attribute:

onclick='System.Diagnostics.Process.Start("http://www.yahoo.com")'

If that doesn't work, there's probably some other command you should use instead. I don't have time to google it right now, so I advise that you do :)

Share this post


Link to post
Share on other sites
erm there's no way this could work , this starts a process on the server (that would , if the command was allowed to run , launch the adress into a new web browser ON the server not on the client machine). There are multiple solutions depending on wether you need to react serverside too or just redirect , if you only need to redirect then do it in JS adding this to the onclick method "window.location=http://www.yahoo.com" , if you need to handle something serverside you'll have to leave the button as it is and then when done doing whatever you want in the click handler use page.request.redirect function.

I don't have an ide handy so i typed all this from memory , syntax/case is prolly very wrong so don't expect copy/paste to work

Share this post


Link to post
Share on other sites
Not if you take out the runat=server. I think, I don't know ASP.NET that well (I've used it before but I'm no expert)

javascript is the best way, or you could use a basic HTML Form:

<FORM METHOD="LINK" ACTION="YOUR LINK HERE"><input type="submit" value="YOUR TEXT HERE"></FORM>

that's a basic HTML linking button without even a trace of ASP.NET.

Share this post


Link to post
Share on other sites
As far as I remember, there is a very straightforward way to do this. Try with Response.Redirect("www.example.com"); in the event-handler code for the OnClick event of your asp:Button.

edit:
For God's sake, don't use all capitals in your markup code, it hurts just looking at it. Asp.net has a lot of built-in functionality, you don't need to emulate it with javascript (which just begs for bugs as it doesn't say anything when an error occurs).

From my own experience I can give you the following advice: do _not_ use regular HTML <form>s without the runat="server" attribute. It just begs for problems. With event handlers in your code-behind you can do everything. Do it _only_ if you are _sure_ what you want to do. Even then, it might lead to problems, as some of the functionality that is built-in in HttpResponse and HtppRequest won't work correctly. If you don't want the page to reload on every button-click, simply use asp:ScriptManager and asp:UpdatePanel. The page will still be reloading, but the user won't notice it, as asp:UpdatePanel uses AJAX. And one final thing - one <form> per .aspx .

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!