How to determine control that fired event

M

milop

Hello.

Using .Net 2.0 and above, how,in the Page_Load event, can I determine what
control triggered the postback?

Thanks in advance,

Mike
 
R

Rafael Malheiros

You could use the sender parameter to get who fired the trigger.
Its a object so you need a cast.
 
M

milop

Hi, Mark. Thanks for the response.

That I know and employ all of it.

Page_Load usually has code to restore state and application data (like
customer information which involves one or more DB round trips), restoring
user controls, etc. There are situations where I do not want such code to
execute when certain controls are clicked because it would be wasteful.

I have modularized functionality into functions and subs and call them in
certain controls' events, but I am looking for a different approach.

Thanks again,

Mike
 
M

milop

Hi Rafael. Thanks for the response.

I found this approach not to be straight forward.

Thanks,

Mike
 
M

milop

Hi, Patrice. Thanks for responding.

I don't know why I never thought of that.

Thank you,

Mike
 
A

Andrew Raastad

Mike, if I could toss in my $.02?
Page_Load usually has code to restore state and application data (like
customer information which involves one or more DB round trips), restoring
user controls, etc. There are situations where I do not want such code to
execute when certain controls are clicked because it would be wasteful.

I had a project a little while back where I had some of the same desires.
Why hit the database every time the page does a postback, why display
controls or sections of the page if they aren't needed, etc.

What we ended up doing was on the first time the page loaded we'd hit the
database, do the logic processing, what have you, and then store all that in
a calss object, and save that object as a Session variable. Then, when the
page would postback from a user input or whatever, we could then restore the
object from the Session, check the properties of the object which designated
how the page should be set up or provide data for items to be bound to, and
so forth. This was all done inside the Page_Init so that by the time the
Page_Load event fired, only the items needed would be processed and sent
back to the user.

We cut load times, processing, and such down to a fraction of the time it
used to take, and also made future expansion, maintenance, and debugging a
breeze.

I know this doesn't answer the question of your original post, and not sure
if this would help you out, but thought I would toss it out there for your
consideration.

-- Andrew
 
A

Andrew Raastad

Mark Rae said:
That's fine for a very small number of concurrent users, but is completely
non-scalable.

Imagine, say, 500 concurrent users and you will could potentially have 500
copies of the page's state stored in Session memory...

You bring up a good point, scalability should always be something that is
considered.... depending on the application being written and where used.
My suggestion was to keep in memory a copy of an object that could contain
datatables/datasets, various strings, longs, or other items as properties,
and who knows what else as it would depend on the need of the application.
So true, you could in effect have a single copy of the object in memory
taking anywhere from just a few KB to a few hundred. But what I would argue
is that even at a couple hundred KB per copy, the environment where massive
numbers of concurrent users would be encountered would dictate this
application be placed on a true server, and today's servers have many (if
not dozens) of GB's of memory. That coupled with effective and efficient
code to destroy objects no longer in use, garbage collection, and other
methods, make using the Session area for storage and retrieval of items as I
mentioned a highly valuable and accessible resource and tool to be
exploited.

You shouldn't be so quick to toss out the "scalability" buzz word and then
summarily dismiss the idea proposed. Mike has not mentioned what
environment this application of his will be run from (Intranet, Internet,
user population, etc.), nor do we know if my suggestion would be utilized in
just a segment of the overall application or be used throughout. If this
process were placed on a public page of a public web site, then yes, there
could potentially be thousands of concurrent sessions... but if this process
Mike's building is on a single page within the admin section of an Intranet
website, there may be less than half a dozen in memory at any given time.

I think it highly unfair of you to so readily judge a suggestion, and
attempt to bias the OP against it just as quickly, without knowing or
further discussing facts surrounding its possible implementation. That and
your "but is completely non-scalable" comment is in fact very false.

-- Andrew

Oh, btw, I was *not* suggesting keeping a copy of the state of the entire
page in memory (that's called ViewState)... I was suggesting having an
object that would have various properties whose values could be used to
designate if controls should be displayed or not, contain a datatable or
dataset that a ListView or GridView could be re-bound to avoiding a trip
back to the database, and other informational items as needed the page could
then access to help decide the state of the controls and such displayed on
the page.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,982
Messages
2,570,186
Members
46,740
Latest member
JudsonFrie

Latest Threads

Top