event for button

Discussion in 'ASP .Net' started by Luke, Apr 22, 2004.

  1. Luke

    Luke Guest

    Hi

    I created web control, with dynamically created buttons,
    I linked them with some event (using Click event),
    so when someone clicks
    this events is executed. Everything is working if page is loaded
    directly from server, but when I return to this page using GoBack in
    browser and then I press button, nothing happens, page is reloaded
    but event is not executing.
    Why?
    Can anybody tell me?

    thanks
    Lu
     
    Luke, Apr 22, 2004
    #1
    1. Advertising

  2. When you dynamically add a control with a corresponding event, you have to
    include the event handler. For example (in C#),

    Button btnGo = new Button();
    btnGo.Text = "GO!";
    btnGo.Click += new EventHandler(btnGo_Click);

    Then, somewhere in your class, you have:

    protected void btnGo_Click(Object objSender, EventArgs evtArgs)
    {
    <Some code goes here>
    }

    Hope this helps!


    Christopher Reed
    Web Applications Supervisor
    City of Lubbock

    >>> Luke<> 7:58:19 AM 4/22/2004 >>>

    Hi

    I created web control, with dynamically created buttons,
    I linked them with some event (using Click event),
    so when someone clicks
    this events is executed. Everything is working if page is loaded
    directly from server, but when I return to this page using GoBack in
    browser and then I press button, nothing happens, page is reloaded
    but event is not executing.
    Why?
    Can anybody tell me?

    thanks
    Lu
     
    Christopher Reed, Apr 22, 2004
    #2
    1. Advertising

  3. Luke

    Rick Spiewak Guest

    And, of course, you have to re-create dynamically created controls on every
    page load...

    "Christopher Reed" <> wrote in message
    news:%...
    > When you dynamically add a control with a corresponding event, you have to
    > include the event handler. For example (in C#),
    >
    > Button btnGo = new Button();
    > btnGo.Text = "GO!";
    > btnGo.Click += new EventHandler(btnGo_Click);
    >
    > Then, somewhere in your class, you have:
    >
    > protected void btnGo_Click(Object objSender, EventArgs evtArgs)
    > {
    > <Some code goes here>
    > }
    >
    > Hope this helps!
    >
    >
    > Christopher Reed
    > Web Applications Supervisor
    > City of Lubbock
    >
    > >>> Luke<> 7:58:19 AM 4/22/2004 >>>

    > Hi
    >
    > I created web control, with dynamically created buttons,
    > I linked them with some event (using Click event),
    > so when someone clicks
    > this events is executed. Everything is working if page is loaded
    > directly from server, but when I return to this page using GoBack in
    > browser and then I press button, nothing happens, page is reloaded
    > but event is not executing.
    > Why?
    > Can anybody tell me?
    >
    > thanks
    > Lu
    >
    >
    >
    >
     
    Rick Spiewak, Apr 23, 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.

Share This Page