Adding the Default.aspx PageTo 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 UserWith 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.
Code Block
Default.aspx.cs
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!
TestingTo 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.
redirect btn asp4 csharp