Server Intellect
 
Home   Asp.Net Tutorials   What's New   Newsletter   More Resources
Tutorial RSS
 
  Categories
Advanced Technologies
AJAX
Internet Browsers
Charts
Controls
Database
Email
Error Handling
File
Graphics
Website Navigation
Network
Performance
User Interface and Themes
Validation
Visual Web Developer
Web Services
XML
Suggest Tutorial


Navigator: Home - Tutorials - Controls - Creating a Redirect Button with ASP.NET 4.0 and C#
Creating a Redirect Button with ASP.NET 4.0 and C#

ASP.Net 4.0 Tutorials V4
Server Intellect Cloud Hosting

ASP.NET Controls Tutorial

This tutorial will demonstrate how to create a button that will redirect the user to a different web page in ASP.NET 4.0 and C#.

Adding the Default.aspx Page
To demonstrate a redirect button we will need to create a simple web site that contains a textbox and a button. At this point I have created a new ASP.NET Empty Web Site. Next, we need to add the web form with our content. To do this:

We used over 10 web hosting companies before we found Server Intellect. Our new cloud server,was set up in less than 24 hours. We were able to confirm our order over the phone. They responded to our inquiries within an hour. Server Intellect's customer support and assistance are the best we've ever experienced.

  1. Right click the project in your solution explorer.
  2. Select add new item...
  3. Select a web form.
  4. Name it 'Default.aspx'.
  5. Click add.
  6. Open Default.aspx up to design mode.
  7. Drag and drop a textbox onto the web form.
    1. Change the ID property of the textbox to 'txtSearch'
  8. Add a line break after txtSearch.
  9. Drag and drop a button underneath txtSearch.
    1. Change the ID propertof the button to 'btnSearch'.
  10. Double click btnSearch to generate the button click event method.

Redirecting the User
With the Default.aspx.cs code behind open for editing, we need to add in the code to redirect the user. I am going to use a simple example of redirecting the user to query a search with Google. Here I will redirect the user to a search based on what they have entered in txtSearch. To do this add the following code into the btnSearch_Click event method.

protected void btnSearch_Click(object sender, EventArgs e)
{
    //redirect the user to google with a search query of the text of our textbox
    Response.Redirect("http://www.google.com/search?q=" + txtSearch.Text);
}

Need help with cloud hosting? Try Server Intellect. We used them for our cloud hosting services and we are very happy with the results!

Testing
To test this out, load up the web site and type something into the text box. Click the button and ensure that you were redirected to Google with a search query of whatever you entered into the textbox.

Download Project Source - Enter your Email to be emailed a link to download the Full Source Project used in this Tutorial!



100% SPAM FREE! We will never sell or rent your email address!



 
  Developer Resources







Server Intellect Rocks