Itai16 Posted February 16, 2017 Share Posted February 16, 2017 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? Link to comment Share on other sites More sharing options...
justsomeguy Posted February 16, 2017 Share Posted February 16, 2017 If you use your browser's developer tools to look at the request, does the comma get submitted with the form data? Link to comment Share on other sites More sharing options...
Itai16 Posted February 16, 2017 Author Share Posted February 16, 2017 I think it still stays. Do you know what should I change in the code? Link to comment Share on other sites More sharing options...
justsomeguy Posted February 16, 2017 Share Posted February 16, 2017 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. Link to comment Share on other sites More sharing options...
Itai16 Posted February 17, 2017 Author Share Posted February 17, 2017 ok thanks. and do you know what should i do to erase any spaces used in text input? Link to comment Share on other sites More sharing options...
justsomeguy Posted February 17, 2017 Share Posted February 17, 2017 You can use a string replace function, or a regular expression replace, or a trim function to trim whitespace from the beginning and end. Link to comment Share on other sites More sharing options...
Itai16 Posted February 18, 2017 Author Share Posted February 18, 2017 Ok thanks the regular expression replace did what I wanted. Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now