Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 3418
  • Last Modified:

Is Request.Form["__EVENTARGUMENT"] always blank if not a postback?

Is Request.Form["__EVENTARGUMENT"] always blank if not a postback?

I'm really only interested in a few controls on the page that cause a postback but I need to initialize something on the initial page load and I want to be sure I won't conflict with some existing code.

Thanks.
0
ZekeLA
Asked:
ZekeLA
  • 3
  • 2
1 Solution
 
abelCommented:
If you want to know whether there's a postback or not, it is much easier to use the this.isPostBack property on your page then to investigate undocumented features that may change whenever there's an update of the software:

if(!this.IsPostBack)
{
   // init controls that should only be initiated when there isn't a postback
   // which is usually almost all of them...
}

Open in new window

0
 
ZekeLAAuthor Commented:
I appreciate your response but I do not want to know if there is a postback.

I inherited code as follows:
    if (Request.Form("__EVENTARGUMENT") == "Something") {...

I need to check for something with !Page.IsPostback prior to that but I am concerned that the old code could be true on the initial page load in which case I still may want the old code to excute as well. Thus my question, is Request.Form("__EVENTARGUMENT") blank on the initial page load?
0
 
abelCommented:
I see, perhaps a bit broader description of __EVENTARGUMENT is more to your help then ;-)

The hidden input element __EVENTARGUMENT is only set when there are controls set to do autopostback. In many cases it will be empty (i.e., when someone clicks a LinkButton, which is also a certain method of auto postback and which also sets the __EVENTARGUMENT, but to an empty value). This means, that sometimes, even on postback, the __EVENTARGUMENT is not there at all.

On initial load, nothing is posted back, period. So the answer is: it is not only blank, it is actually nothing (null) because the data has not become part of a form request yet.

This also means: a normal load (GET request), works, but when you come from another page which did a postback, the __EVENTARGUMENT will be set with whatever is clicked on that referring page.
0
 
ZekeLAAuthor Commented:
You said, "This also means: a normal load (GET request), works, but when you come from another page which did a postback, the __EVENTARGUMENT will be set with whatever is clicked on that referring page."

This is only if you use cross page posting, correct?
0
 
abelCommented:
Yes, that's indeed exactly what I mean. The same effect can happen if you would use Server.Transfer in your code behind (from another page to this one), but that's essentially the same as cross page posting and is not a recommended practice anyway ;-)
0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

  • 3
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now