Solved

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

Posted on 2009-07-14
5
3,311 Views
Last Modified: 2013-11-07
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
Comment
Question by:ZekeLA
  • 3
  • 2
5 Comments
 
LVL 39

Expert Comment

by:abel
ID: 24854689
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
 
LVL 1

Author Comment

by:ZekeLA
ID: 24854727
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
 
LVL 39

Accepted Solution

by:
abel earned 500 total points
ID: 24855139
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
 
LVL 1

Author Comment

by:ZekeLA
ID: 24858557
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
 
LVL 39

Expert Comment

by:abel
ID: 24859361
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: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

More often than not, we developers are confronted with a need: a need to make some kind of magic happen via code. Whether it is for a client, for the boss, or for our own personal projects, the need must be satisfied. Most of the time, the Framework…
Performance in games development is paramount: every microsecond counts to be able to do everything in less than 33ms (aiming at 16ms). C# foreach statement is one of the worst performance killers, and here I explain why.
Established in 1997, Technology Architects has become one of the most reputable technology solutions companies in the country. TA have been providing businesses with cost effective state-of-the-art solutions and unparalleled service that is designed…
In an interesting question (https://www.experts-exchange.com/questions/29008360/) here at Experts Exchange, a member asked how to split a single image into multiple images. The primary usage for this is to place many photographs on a flatbed scanner…

840 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question