Solved

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

Posted on 2009-07-14
5
3,271 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

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

Question has a verified solution.

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

Just a quick little trick I learned recently.  Now that I'm using jQuery with abandon in my asp.net applications, I have grown tired of the following syntax:      (CODE) I suppose it just offends my sense of decency to put inline VBScript on a…
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
This Micro Tutorial will teach you how to censor certain areas of your screen. The example in this video will show a little boy's face being blurred. This will be demonstrated using Adobe Premiere Pro CS6.
This Micro Tutorial hows how you can integrate  Mac OSX to a Windows Active Directory Domain. Apple has made it easy to allow users to bind their macs to a windows domain with relative ease. The following video show how to bind OSX Mavericks to …

920 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

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now