HttpMethod and PostBack Testing
-
Just a quick question. Is this test logical or possible in ASP.NET? If so, under what scenario(s) would you expect to see such a positive result of the test. Thanks
if (Request.HttpMethod == "POST" && !IsPostBack)
{...}Just because we can; does not mean we should.
-
Just a quick question. Is this test logical or possible in ASP.NET? If so, under what scenario(s) would you expect to see such a positive result of the test. Thanks
if (Request.HttpMethod == "POST" && !IsPostBack)
{...}Just because we can; does not mean we should.
I ain't no web-programmer, but sounds like homework, and I know where the documentation is, so shouldn't be too hard to come up with something. Let's try. HttpRequest.HttpMethod[^]
Gets the HTTP data transfer method (such as GET, POST, or HEAD) used by the client.
Docs also state it's a
String
, so the first part of the evaluation looks correct. The English implies that the Request was aPOST
action on the server.IsPostBack
looks like a property, not a method. Guess it must be part of the Page[^].Gets a value that indicates whether the page is being rendered for the first time or is being loaded in response to a postback.
Ah, interesting. So, the block would be executed if:
- It's being POST-ed
- It's not a postback (meaning, the page is being rendered the first time)
The action is determined in the
Form
;<form name="input" action="html_form_action.asp" method="post">
..and that is why I kinda like MSDN. Hope this helps a bit :)
Bastard Programmer from Hell :suss: if you can't read my code, try converting it here[^]
-
I ain't no web-programmer, but sounds like homework, and I know where the documentation is, so shouldn't be too hard to come up with something. Let's try. HttpRequest.HttpMethod[^]
Gets the HTTP data transfer method (such as GET, POST, or HEAD) used by the client.
Docs also state it's a
String
, so the first part of the evaluation looks correct. The English implies that the Request was aPOST
action on the server.IsPostBack
looks like a property, not a method. Guess it must be part of the Page[^].Gets a value that indicates whether the page is being rendered for the first time or is being loaded in response to a postback.
Ah, interesting. So, the block would be executed if:
- It's being POST-ed
- It's not a postback (meaning, the page is being rendered the first time)
The action is determined in the
Form
;<form name="input" action="html_form_action.asp" method="post">
..and that is why I kinda like MSDN. Hope this helps a bit :)
Bastard Programmer from Hell :suss: if you can't read my code, try converting it here[^]
Thanks for the reply, not quite the answer I was hoping for, but thanks anyway. p.s. its not "homework" in the traditional sense but rather me attempting to expand my knowledge on my own time.
Just because we can; does not mean we should.
-
Thanks for the reply, not quite the answer I was hoping for, but thanks anyway. p.s. its not "homework" in the traditional sense but rather me attempting to expand my knowledge on my own time.
Just because we can; does not mean we should.
KaptinKrunch wrote:
me attempting to expand my knowledge
Good to hear that there are still people learning voluntarily :thumbsup:
KaptinKrunch wrote:
not quite the answer I was hoping for, but thanks anyway.
'twas a bit rude, but it seemed like a good idea to explain how I reached the conclusion on what the code "theoretically" would do. If you have suggestions on how my answers would be improved, by all means, hit me :-D
Bastard Programmer from Hell :suss: if you can't read my code, try converting it here[^]
-
Just a quick question. Is this test logical or possible in ASP.NET? If so, under what scenario(s) would you expect to see such a positive result of the test. Thanks
if (Request.HttpMethod == "POST" && !IsPostBack)
{...}Just because we can; does not mean we should.