Jump to content
Sign in to follow this  
Itai16

ASP Response.redirect

Recommended Posts

I have tried to add a search bar to my own website that will send the user to another page in my project, the value in the search box will send the user to the page.

 

Main.aspx: //The main page
<form id=search1 method=get action=search.aspx>
<input type=text name=search id=search placeholder="Search Here" />
<button type=submit name=search id=go>Search</button>
</form>
Search.aspx.cs: //The page that will deal with the search info
string sea = Request["search"];
Response.Redirect(sea+(".aspx"));
As an example, there is a page called "2016" and writing it in the text box followed by submitting the form will send the user to the page 2016.aspx but the address bar says: localhost:8525//2016,.aspx
Why is there a comma there? Do i have to change something with my code?

Share this post


Link to post
Share on other sites

If you use your browser's developer tools to look at the request, does the comma get submitted with the form data?

Share this post


Link to post
Share on other sites

It's always best to verify instead of assume. Assumptions lead to problems. If the form is submitting multiple elements with the name "search", for example, then that's probably going to be an array or comma-separated list. And you can verify that by looking at your browser's developer tools. If I'm going to assume, then I will assume that since your text field has the name "search", and your submit button also has the name "search", then it's probably submitting multiple values for that.

Share this post


Link to post
Share on other sites

You can use a string replace function, or a regular expression replace, or a trim function to trim whitespace from the beginning and end.

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
Sign in to follow this  

×
×
  • Create New...