Dynamic buttons and PostBack

A

andrei

Hi Group,

I have an aspx form with a variable number of buttons added dynamically,
with id's like b01, b02, b03...
Whenever I click one of these buttons, the form is posted back.

I need to find out which of the buttons triggered the postback *in the
Page_Load* - here I have some code that needs to know which button was
clicked so it will generate different output for the page.

I also have code for each <btn>_Click, but those subs are executed after the
Page_Load, so at that time the design of the page is already done (dynamic
creation of controls).

Anyone knows how to find which button called the postback?

Thanks !

Andrei.
 
G

Guest

Why in Page_Load?

NOTE: Page_Load is used to what? Load the page. it is not called
Page_Load_And_Figure_Out_Everything_You_Are_Doing.

To properly find out where you are, dynamically wire the dynamic buttons to
a particular event handler. Then, you can use sender to determine who was
responsible for this trip. It does not break the model.

Unfortunately, I have seen too many examples where a person used Page_Load
as a general handler for everything a page does. That is not its purpose. If
you have an else branch, every submit should take advantage of it. There is a
reason for button event handlers, and a way to dynamically wire them. Why use
Page_Load as if it was Page_Do_Every_Submit?


NoTE: The syntax for "dynamic" wiring is very easy in C#. Remember, however,
that event handling is simply a delegate call and you can do it in VB.NET, as
well.

---

Gregory A. Beamer
MVP; MCP: +I, SE, SD, DBA

***************************
Think Outside the Box!
***************************
 

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

Forum statistics

Threads
473,774
Messages
2,569,599
Members
45,175
Latest member
Vinay Kumar_ Nevatia
Top