Button Click events only firing on second click

B

Ben Fidge

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
 
A

avnrao

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.
 
B

Ben Fidge

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
 
S

S. Justin Gengo

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
 
B

Ben Fidge

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
 

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,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top