How to wire a button click event in a composite control?

R

Russ

I just can't seem to do it. In my composite control I add a button:

Button Db = new Button ();
Db.ID = "DedButton" + i;
Db.Style.Add ("Position", "Absolute");
Db.Style.Add ("Left", "300px");
Db.Style.Add ("Top", "290px");
Db.Text = "Edit Deductions";
Db.Click += new System.EventHandler(DedButton_Click);
pv.Controls.Add (Db);

(pv is a pageview control)

Then in the same class I have:

private void DedButton_Click (object sender, System.EventArgs e)
{

}

I put a breakpoint at the entry point of DedButton_Click, but it never
gets there. Clicking the button does cause post back, but the event
never fires. I have had the same problem with the OnChange event for
a Drop Down List. I gave up on the DDL and am now trying to make a
simple button work.

HALP!

Thanks, Russ
 
J

Jos

Russ said:
I just can't seem to do it. In my composite control I add a button:

Button Db = new Button ();
Db.ID = "DedButton" + i;
Db.Style.Add ("Position", "Absolute");
Db.Style.Add ("Left", "300px");
Db.Style.Add ("Top", "290px");
Db.Text = "Edit Deductions";
Db.Click += new System.EventHandler(DedButton_Click);
pv.Controls.Add (Db);

(pv is a pageview control)

Then in the same class I have:

private void DedButton_Click (object sender, System.EventArgs e)
{

}

I put a breakpoint at the entry point of DedButton_Click, but it never
gets there. Clicking the button does cause post back, but the event
never fires. I have had the same problem with the OnChange event for
a Drop Down List. I gave up on the DDL and am now trying to make a
simple button work.

Does your composite control re-create the button on postback?
If not, it can not handle events, because it's not there anymore.
 
R

Russ

THANK YOU Jos ! You probably can't imagine the amount of time I have
spent trying to get some form of this working. Yes, I was recreating
it on postback. But when you asked, I thought about the fact that I
do not add the event handler when I recreate it. I didn't think I
needed it because I don't display the window again after the event is
handled.

Whew! Now I can get on with the job.

Thanks again Jos.

Regards, Russ
 

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,755
Messages
2,569,537
Members
45,022
Latest member
MaybelleMa

Latest Threads

Top