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

Discussion in 'ASP .Net Web Controls' started by Russ, Jul 21, 2004.

  1. Russ

    Russ Guest

    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
    Russ, Jul 21, 2004
    #1
    1. Advertising

  2. Russ

    Jos Guest

    Russ wrote:
    > 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.

    --

    Jos
    Jos, Jul 22, 2004
    #2
    1. Advertising

  3. Russ

    Russ Guest

    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

    On Thu, 22 Jul 2004 10:09:24 +0200, "Jos"
    <> wrote:

    >Russ wrote:
    >> 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.
    Russ, Jul 22, 2004
    #3
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Purvi T
    Replies:
    0
    Views:
    820
    Purvi T
    Oct 19, 2004
  2. Derrick

    wire enter to button click

    Derrick, Jun 29, 2004, in forum: ASP .Net
    Replies:
    3
    Views:
    325
    Derrick
    Jul 2, 2004
  3. Chu
    Replies:
    2
    Views:
    894
    Winista
    Apr 10, 2006
  4. Amy
    Replies:
    0
    Views:
    959
  5. quoclinh
    Replies:
    4
    Views:
    133
    quoclinh
    Jun 26, 2007
Loading...

Share This Page