Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

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

Posted on 2009-07-14
5
Medium Priority
?
3,390 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 2000 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

Stressed Out?

Watch some penguins on the livecam!

Question has a verified solution.

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

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…
This article is for Object-Oriented Programming (OOP) beginners. An Interface contains declarations of events, indexers, methods and/or properties. Any class which implements the Interface should provide the concrete implementation for each Inter…
This is my first video review of Microsoft Bookings, I will be doing a part two with a bit more information, but wanted to get this out to you folks.
In this video, Percona Director of Solution Engineering Jon Tobin discusses the function and features of Percona Server for MongoDB. How Percona can help Percona can help you determine if Percona Server for MongoDB is the right solution for …

705 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