Solved

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

Posted on 2009-07-14
5
3,343 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

PeopleSoft Has Never Been Easier

PeopleSoft Adoption Made Smooth & Simple!

On-The-Job Training Is made Intuitive & Easy With WalkMe's On-Screen Guidance Tool.  Claim Your Free WalkMe Account Now

Question has a verified solution.

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

IntroductionWhile developing web applications, a single page might contain many regions and each region might contain many number of controls with the capability to perform  postback. Many times you might need to perform some action on an ASP.NET po…
Today I had a very interesting conundrum that had to get solved quickly. Needless to say, it wasn't resolved quickly because when we needed it we were very rushed, but as soon as the conference call was over and I took a step back I saw the correct …
I've attached the XLSM Excel spreadsheet I used in the video and also text files containing the macros used below. https://filedb.experts-exchange.com/incoming/2017/03_w12/1151775/Permutations.txt https://filedb.experts-exchange.com/incoming/201…
How to Install VMware Tools in Red Hat Enterprise Linux 6.4 (RHEL 6.4) Step-by-Step Tutorial

710 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