Jump to content


Photo

ASP Response.redirect

ASP C#.NET Response.Redirect

  • Please log in to reply
6 replies to this topic

#1 Itai16

Itai16

    Newbie

  • Members
  • Pip
  • 4 posts

Posted 16 February 2017 - 06:07 PM

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?


#2 justsomeguy

justsomeguy

    More Human Than Human

  • Moderator
  • PipPipPipPipPipPipPip
  • 29,654 posts
  • Gender:Male
  • Location:Phoenix
  • Languages:Focusing on PHP and JavaScript

Posted 16 February 2017 - 06:40 PM

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

Know your history: Babbage | Lovelace | Turing | Hopper | Ritchie
ConTEXT Sublime Text Opera PHP MySQL phpMyAdmin
Use a debugger: Firefox, IE, Chrome, Safari, or Opera
Know the foundations of computer science: algorithms, machine architectures, data structures, etc. Don't just blindly copy techniques from application to application. Know what you are doing, that it works, and why it works. Don't think you know what the industry will be in five years time or what you'll be doing then, so gather a portfolio of general and useful skills. Try to write better, more principled code. Work to make "programming" more of a professional activity and less of a low-level "hacking" activity (programming is also a craft, but not just a craft). Learn from the classics in the field and the better advanced textbooks; don't be satisfied with the easily digested "how to" guides and online documentation - it's shallow.
-- Bjarne Stroustrup

He that teaches himself has a fool for a master.
-- Benjamin Franklin (paraphrased)


#3 Itai16

Itai16

    Newbie

  • Members
  • Pip
  • 4 posts

Posted 16 February 2017 - 07:58 PM

I think it still stays. Do you know what should I change in the code?



#4 justsomeguy

justsomeguy

    More Human Than Human

  • Moderator
  • PipPipPipPipPipPipPip
  • 29,654 posts
  • Gender:Male
  • Location:Phoenix
  • Languages:Focusing on PHP and JavaScript

Posted 16 February 2017 - 08:13 PM

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.

Know your history: Babbage | Lovelace | Turing | Hopper | Ritchie
ConTEXT Sublime Text Opera PHP MySQL phpMyAdmin
Use a debugger: Firefox, IE, Chrome, Safari, or Opera
Know the foundations of computer science: algorithms, machine architectures, data structures, etc. Don't just blindly copy techniques from application to application. Know what you are doing, that it works, and why it works. Don't think you know what the industry will be in five years time or what you'll be doing then, so gather a portfolio of general and useful skills. Try to write better, more principled code. Work to make "programming" more of a professional activity and less of a low-level "hacking" activity (programming is also a craft, but not just a craft). Learn from the classics in the field and the better advanced textbooks; don't be satisfied with the easily digested "how to" guides and online documentation - it's shallow.
-- Bjarne Stroustrup

He that teaches himself has a fool for a master.
-- Benjamin Franklin (paraphrased)


#5 Itai16

Itai16

    Newbie

  • Members
  • Pip
  • 4 posts

Posted 17 February 2017 - 05:45 AM

ok thanks. and do you know what should i do to erase any spaces used in text input?



#6 justsomeguy

justsomeguy

    More Human Than Human

  • Moderator
  • PipPipPipPipPipPipPip
  • 29,654 posts
  • Gender:Male
  • Location:Phoenix
  • Languages:Focusing on PHP and JavaScript

Posted 17 February 2017 - 06:45 PM

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

Know your history: Babbage | Lovelace | Turing | Hopper | Ritchie
ConTEXT Sublime Text Opera PHP MySQL phpMyAdmin
Use a debugger: Firefox, IE, Chrome, Safari, or Opera
Know the foundations of computer science: algorithms, machine architectures, data structures, etc. Don't just blindly copy techniques from application to application. Know what you are doing, that it works, and why it works. Don't think you know what the industry will be in five years time or what you'll be doing then, so gather a portfolio of general and useful skills. Try to write better, more principled code. Work to make "programming" more of a professional activity and less of a low-level "hacking" activity (programming is also a craft, but not just a craft). Learn from the classics in the field and the better advanced textbooks; don't be satisfied with the easily digested "how to" guides and online documentation - it's shallow.
-- Bjarne Stroustrup

He that teaches himself has a fool for a master.
-- Benjamin Franklin (paraphrased)


#7 Itai16

Itai16

    Newbie

  • Members
  • Pip
  • 4 posts

Posted 18 February 2017 - 09:57 AM

Ok thanks the regular expression replace did what I wanted.







Also tagged with one or more of these keywords: ASP, C#.NET, Response.Redirect

0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users