2 controls on the same page and wrong events fire

J

justengland

I have a button control that uses the <button> tag. I use the render
control method. I have the name attribute set to the control unique
id.

When I have 2 of these buttons on the same page, the page gets confused
as to what control fired the event. How can I make it work. Basically
it calls the last event in the list no matter which button I use to
cause the postback. I use the __dopostback to call the postback. I
have tried both calls
psudo code of course
__dopostback('controlname','');
and
__dopostback('unique id','');

I am sure that many people have had this issue so please help me.

Thanks
Justin
 
J

justengland

I have set the unique id = to
<button id='unique id' onclick=__dopostback('unique id','' >
 
L

lisa

Well, you didn't say if you tried the ClientID. Have you looked in
debug mode? Are you using INamingContainer?

The reason I ask is that if you look at the HTML that gets rendered,
you'll probably see that the name and the id are different. One has an
underscore and the other has a colon. I believe it's the id that has
the underscore. The thing is, it's the name that gets posted back. So
if you're posting back the id, it may not be identifying the control
correctly.

Check it out.

Lisa
 
J

justengland

Method 1
<button ID='btOK' Name='btOK' onclick="__doPostBack('btOK','');">
<button ID='btOK1' Name='btOK1' onclick="__doPostBack('btOK1','');">
'Postback fires but no events are raised

Method 2
<button ID='btOK1' Name='_ctl0' onclick="__doPostBack('_ctl0','');">
<button ID='btOK' Name='_ctl1' onclick="__doPostBack('_ctl1','');">
'btOK click server side event is handled by both controls

method 3
<button ID='_ctl0' Name='btOK1' onclick="__doPostBack('_ctl0','');">
<button ID='_ctl1' Name='btOK' onclick="__doPostBack('_ctl1','');">
'This worked

I guess this is the opposite of IPostBackDataHandler which needs the
unique id as the name.

I am not sure what bennifit the INamingContainer is since it has 0
methods defined, but I included it anyway. Thanks for all of your
help. You made me try all combonations of the javascript, which is
what fixed the problem.
 

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,536
Members
45,007
Latest member
obedient dusk

Latest Threads

Top