Button Click events only firing on second click

Discussion in 'ASP .Net' started by Ben Fidge, Jun 15, 2004.

  1. Ben Fidge

    Ben Fidge Guest

    I've got a problem where some buttons placed on a user
    control are only firing their OnClick events when the
    user clicks on them for the second time.

    I've got the situation where some common functionality
    (Insert/Edit/Save/Cancel) is wrapped up in a user
    control. This control is embedded on several other user
    controls.

    I don't know if this is relevant or not but the latter
    user controls (hosting the Edit/Save etc control)
    mentioned above are loaded dynamically at runtime into a
    PlaceHolder using Page.LoadControl.

    So running the project - The first time the user clicks
    on one of the buttons nothing happens, the second time,
    and every time thereafter, the OnClick event gets fired
    as it should.

    I've compared the source HTML in the browser for both
    scenarios, and there is no difference between them

    Any ideas?

    Kind regards

    Ben
     
    Ben Fidge, Jun 15, 2004
    #1
    1. Advertising

  2. Ben Fidge

    avnrao Guest

    i think the event handlers are not mapped for the first time and second time
    onwards they are mapped.
    can you post your code..we can try to debug it.

    Av.

    "Ben Fidge" <> wrote in message
    news:1cca701c452d2$0ab9e020$...
    > I've got a problem where some buttons placed on a user
    > control are only firing their OnClick events when the
    > user clicks on them for the second time.
    >
    > I've got the situation where some common functionality
    > (Insert/Edit/Save/Cancel) is wrapped up in a user
    > control. This control is embedded on several other user
    > controls.
    >
    > I don't know if this is relevant or not but the latter
    > user controls (hosting the Edit/Save etc control)
    > mentioned above are loaded dynamically at runtime into a
    > PlaceHolder using Page.LoadControl.
    >
    > So running the project - The first time the user clicks
    > on one of the buttons nothing happens, the second time,
    > and every time thereafter, the OnClick event gets fired
    > as it should.
    >
    > I've compared the source HTML in the browser for both
    > scenarios, and there is no difference between them
    >
    > Any ideas?
    >
    > Kind regards
    >
    > Ben
     
    avnrao, Jun 15, 2004
    #2
    1. Advertising

  3. Ben Fidge

    Ben Fidge Guest

    I've put a breakpoint on the InitializeComponent method
    of my UserControl, and the events are setup during the
    page load both times. It's got to be something going on
    client-side, even though I'm sure the javascript
    __doPostBack is setup properly.

    Where can I send the source code to you? I'm using a
    browser based newsgroup reader as NNTP is blocked on our
    firewall, and I can't attach files.

    Thanks

    Ben

    >-----Original Message-----
    >i think the event handlers are not mapped for the first

    time and second time
    >onwards they are mapped.
    >can you post your code..we can try to debug it.
    >
    >Av.
    >
    >"Ben Fidge" <> wrote in message
    >news:1cca701c452d2$0ab9e020$...
    >> I've got a problem where some buttons placed on a user
    >> control are only firing their OnClick events when the
    >> user clicks on them for the second time.
    >>
    >> I've got the situation where some common functionality
    >> (Insert/Edit/Save/Cancel) is wrapped up in a user
    >> control. This control is embedded on several other user
    >> controls.
    >>
    >> I don't know if this is relevant or not but the latter
    >> user controls (hosting the Edit/Save etc control)
    >> mentioned above are loaded dynamically at runtime into

    a
    >> PlaceHolder using Page.LoadControl.
    >>
    >> So running the project - The first time the user clicks
    >> on one of the buttons nothing happens, the second time,
    >> and every time thereafter, the OnClick event gets fired
    >> as it should.
    >>
    >> I've compared the source HTML in the browser for both
    >> scenarios, and there is no difference between them
    >>
    >> Any ideas?
    >>
    >> Kind regards
    >>
    >> Ben

    >
    >
    >.
    >
     
    Ben Fidge, Jun 15, 2004
    #3
  4. Ben,

    I had this same problem on a site I built. I'm not positive if this if the
    fix or not, but what seemed to work is setting the client id of the user
    control.

    What I did is, in the page load of each user control, I set it's client id
    like this:

    Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
    System.EventArgs) Handles MyBase.Load

    Me.ID = "StampFactsControl"



    End Sub

    This seems to have taken care of the problem, but I don't have any
    confirmation that this is what fixed my project. Try it out.

    Would you post here if it does fix the problem? I can't be positive that
    some other change I made didn't fix things, but if it works for you then I
    think that would be confirmation enough.


    --
    Sincerely,

    S. Justin Gengo, MCP
    Web Developer / Programmer

    www.aboutfortunate.com

    "Out of chaos comes order."
    Nietzsche
    "Ben Fidge" <> wrote in message
    news:1cca701c452d2$0ab9e020$...
    > I've got a problem where some buttons placed on a user
    > control are only firing their OnClick events when the
    > user clicks on them for the second time.
    >
    > I've got the situation where some common functionality
    > (Insert/Edit/Save/Cancel) is wrapped up in a user
    > control. This control is embedded on several other user
    > controls.
    >
    > I don't know if this is relevant or not but the latter
    > user controls (hosting the Edit/Save etc control)
    > mentioned above are loaded dynamically at runtime into a
    > PlaceHolder using Page.LoadControl.
    >
    > So running the project - The first time the user clicks
    > on one of the buttons nothing happens, the second time,
    > and every time thereafter, the OnClick event gets fired
    > as it should.
    >
    > I've compared the source HTML in the browser for both
    > scenarios, and there is no difference between them
    >
    > Any ideas?
    >
    > Kind regards
    >
    > Ben
     
    S. Justin Gengo, Jun 15, 2004
    #4
  5. Ben Fidge

    Ben Fidge Guest

    It works!!!!

    Nice one. I would never have thought of that myself!

    In my high-level .aspx page, I have a method called
    LoadScreen that loads in the appropriate UserControl. I
    have a TreeView control and I want to display a different
    UserControl according to the type of node clicked on. In
    the SelecvtedNodeIndexChange event I call Loadscreen

    Instead of putting the ID="???" in the UserControls
    Page_Load, I assign an ID after calling Page.LoadControl.
    As I'm only ever going to have one UserControl on-screen
    at a time I just assign a generic name (ctrlCurrent).
    That way I don't have to remember to assign an ID in
    every page_load of every control.

    Thankyou very much. That has been bugging me for days.

    Ben

    >-----Original Message-----
    >Ben,
    >
    >I had this same problem on a site I built. I'm not

    positive if this if the
    >fix or not, but what seemed to work is setting the

    client id of the user
    >control.
    >
    >What I did is, in the page load of each user control, I

    set it's client id
    >like this:
    >
    >Private Sub Page_Load(ByVal sender As System.Object,

    ByVal e As
    >System.EventArgs) Handles MyBase.Load
    >
    > Me.ID = "StampFactsControl"
    >
    >
    >
    >End Sub
    >
    >This seems to have taken care of the problem, but I

    don't have any
    >confirmation that this is what fixed my project. Try it

    out.
    >
    >Would you post here if it does fix the problem? I can't

    be positive that
    >some other change I made didn't fix things, but if it

    works for you then I
    >think that would be confirmation enough.
    >
    >
    >--
    >Sincerely,
    >
    >S. Justin Gengo, MCP
    >Web Developer / Programmer
    >
    >www.aboutfortunate.com
    >
    >"Out of chaos comes order."
    > Nietzsche
    >"Ben Fidge" <> wrote in message
    >news:1cca701c452d2$0ab9e020$...
    >> I've got a problem where some buttons placed on a user
    >> control are only firing their OnClick events when the
    >> user clicks on them for the second time.
    >>
    >> I've got the situation where some common functionality
    >> (Insert/Edit/Save/Cancel) is wrapped up in a user
    >> control. This control is embedded on several other user
    >> controls.
    >>
    >> I don't know if this is relevant or not but the latter
    >> user controls (hosting the Edit/Save etc control)
    >> mentioned above are loaded dynamically at runtime into

    a
    >> PlaceHolder using Page.LoadControl.
    >>
    >> So running the project - The first time the user clicks
    >> on one of the buttons nothing happens, the second time,
    >> and every time thereafter, the OnClick event gets fired
    >> as it should.
    >>
    >> I've compared the source HTML in the browser for both
    >> scenarios, and there is no difference between them
    >>
    >> Any ideas?
    >>
    >> Kind regards
    >>
    >> Ben

    >
    >
    >.
    >
     
    Ben Fidge, Jun 15, 2004
    #5
  6. Ben,

    Your welcome. Thanks for confirming this fix for me!

    --
    Sincerely,

    S. Justin Gengo, MCP
    Web Developer / Programmer

    www.aboutfortunate.com

    "Out of chaos comes order."
    Nietzsche
    "Ben Fidge" <> wrote in message
    news:1c6ff01c452e2$53e3efb0$...
    > It works!!!!
    >
    > Nice one. I would never have thought of that myself!
    >
    > In my high-level .aspx page, I have a method called
    > LoadScreen that loads in the appropriate UserControl. I
    > have a TreeView control and I want to display a different
    > UserControl according to the type of node clicked on. In
    > the SelecvtedNodeIndexChange event I call Loadscreen
    >
    > Instead of putting the ID="???" in the UserControls
    > Page_Load, I assign an ID after calling Page.LoadControl.
    > As I'm only ever going to have one UserControl on-screen
    > at a time I just assign a generic name (ctrlCurrent).
    > That way I don't have to remember to assign an ID in
    > every page_load of every control.
    >
    > Thankyou very much. That has been bugging me for days.
    >
    > Ben
    >
    > >-----Original Message-----
    > >Ben,
    > >
    > >I had this same problem on a site I built. I'm not

    > positive if this if the
    > >fix or not, but what seemed to work is setting the

    > client id of the user
    > >control.
    > >
    > >What I did is, in the page load of each user control, I

    > set it's client id
    > >like this:
    > >
    > >Private Sub Page_Load(ByVal sender As System.Object,

    > ByVal e As
    > >System.EventArgs) Handles MyBase.Load
    > >
    > > Me.ID = "StampFactsControl"
    > >
    > >
    > >
    > >End Sub
    > >
    > >This seems to have taken care of the problem, but I

    > don't have any
    > >confirmation that this is what fixed my project. Try it

    > out.
    > >
    > >Would you post here if it does fix the problem? I can't

    > be positive that
    > >some other change I made didn't fix things, but if it

    > works for you then I
    > >think that would be confirmation enough.
    > >
    > >
    > >--
    > >Sincerely,
    > >
    > >S. Justin Gengo, MCP
    > >Web Developer / Programmer
    > >
    > >www.aboutfortunate.com
    > >
    > >"Out of chaos comes order."
    > > Nietzsche
    > >"Ben Fidge" <> wrote in message
    > >news:1cca701c452d2$0ab9e020$...
    > >> I've got a problem where some buttons placed on a user
    > >> control are only firing their OnClick events when the
    > >> user clicks on them for the second time.
    > >>
    > >> I've got the situation where some common functionality
    > >> (Insert/Edit/Save/Cancel) is wrapped up in a user
    > >> control. This control is embedded on several other user
    > >> controls.
    > >>
    > >> I don't know if this is relevant or not but the latter
    > >> user controls (hosting the Edit/Save etc control)
    > >> mentioned above are loaded dynamically at runtime into

    > a
    > >> PlaceHolder using Page.LoadControl.
    > >>
    > >> So running the project - The first time the user clicks
    > >> on one of the buttons nothing happens, the second time,
    > >> and every time thereafter, the OnClick event gets fired
    > >> as it should.
    > >>
    > >> I've compared the source HTML in the browser for both
    > >> scenarios, and there is no difference between them
    > >>
    > >> Any ideas?
    > >>
    > >> Kind regards
    > >>
    > >> Ben

    > >
    > >
    > >.
    > >
     
    S. Justin Gengo, Jun 15, 2004
    #6
    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. panik
    Replies:
    0
    Views:
    448
    panik
    Dec 4, 2003
  2. =?Utf-8?B?U2hvdXJpZQ==?=
    Replies:
    1
    Views:
    7,899
    =?Utf-8?B?U2hvdXJpZQ==?=
    Jan 21, 2004
  3. =?Utf-8?B?Vmk=?=

    Button Click Events not firing .NET 2.0

    =?Utf-8?B?Vmk=?=, Jan 29, 2006, in forum: ASP .Net
    Replies:
    1
    Views:
    1,095
    =?Utf-8?B?UGV0ZXIgQnJvbWJlcmcgW0MjIE1WUF0=?=
    Jan 29, 2006
  4. SevDer
    Replies:
    2
    Views:
    1,304
    Walter Wang [MSFT]
    Nov 13, 2007
  5. WISEMANOFNARNIA

    A button that only works on second click - why?

    WISEMANOFNARNIA, Dec 9, 2008, in forum: ASP .Net
    Replies:
    2
    Views:
    946
    WISEMANOFNARNIA
    Dec 11, 2008
Loading...

Share This Page