Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Event Identification

Status
Not open for further replies.

crystalized

Programmer
Jul 10, 2000
390
CA
Hello All,

I have been looking but have not found what I am looking for. I am wondering if it is possible in the page load event to know what event or action triggered the postback that is happening.

So if I have a button on the page with a click event handler, can I tell in the page load if the button triggered the postback or if it was something else that triggered the postback?

If anyone can direct me to a relevant resource or provide a little snippet I would be very appreciative. Crystal
crystalized_s@yahoo.com

--------------------------------------------------

Experience is one thing you can't get for nothing.

-Oscar Wilde

 
No, I'm afraid not... events are raised after the page_load event.

The best workaround for this that I have found for this (if you just can't wait -- which would be best) is to have the button clicked set a variable, which you can evaluate with request.form() in the page_load.

Be warned, however. I started down this path, and before long, your .NET code is as hard to read as your asp classic was. It's really a nightmare -- with this object and that object all floating around everywhere. **shivers**

What specifically do you need, and maybe we can help you to formulate a strategy to get it done w/o doing it the "wrong" way.

:)
paul
penny1.gif
penny1.gif
 
Basically what I need to accomplish is for my page to do a task when a checkbox is clicked. Using a web control with autopostback allowed me to complete this task however it also causes the postback code to execute in the page. So in my postback code I needed a way to branch based on whether the page was postbacked due to the checkbox or due to the person doing something else (hitting enter, clicking a button etc)

So in the end what I did was this:
1. Added an onclick attribute to the checkbox,
2. Set the autopostback on the checkbox to false,
3. Wrote a javascript function that changed a hidden html element value based on the checkbox state before submitting the page,
4. In my code behind I declared a variable representing the hidden html element,
5. In my page load I do a test on the value of the hidden control and branch based on the value.
6. Removed the eventhandler for the checkbox control.

In the end I think this was a case of me relying on some of the built in functionality to make things easy (autopostback) - where it really was not appropriate to do so.
Crystal
crystalized_s@yahoo.com

--------------------------------------------------

Experience is one thing you can't get for nothing.

-Oscar Wilde

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top