Click here to Skip to main content
15,886,689 members
Please Sign up or sign in to vote.
5.00/5 (1 vote)
See more:
i have two panel in ma form. panel1 with button1 on it at location let say x:10,y:10 and panel2 with button 2 on it at location x:10,y:10.

what actually button1 do:- it hide panel1 and shows panel2 at the same location.

but whenever i click on button1 twice after completion its process it fire button2 click event,

plz help me ASAP
Posted

Hi Neeraj,

The reason behind this cause is called "<b>Event Bubbling</b>" in JavaScript. It means the Browser catches the event for every underlying element on a particular point. in order to override this behavior, add these code lines after you code in JS function which is being called on button1 click but just before the closing parenthesis of the function:
JavaScript
function stopEvent(evnt) {
    if (evnt.stopPropagation) {
             evnt.stopPropagation();
     }
     else {
        evnt.cancelBubble = true;
     }
   }


the code above will prevent the event bubbling after the code inside your js function is executed.

Hope this helps!
Happy Coding:)

Sunny K
 
Share this answer
 
Comments
neeraj@max 5-Nov-12 3:04am    
hello sunny... thanks for your quick response....

i work on window mobile app and we cant use js queries in it.

if you have anythng for window plz let me know.

thanks once again.
Sunny_Kumar_ 5-Nov-12 3:41am    
would be great if u share the code what you've tried yet, so that we can get a better picture of the situation. thanks.
neeraj@max 5-Nov-12 5:39am    
i was trying to put snapshots but unable to make it here... can i have your mail id so, i can send it to you...

it would be more clear by images instaed of code actually.
neeraj@max 5-Nov-12 5:58am    
private void Form1_Load(object sender, EventArgs e)
{
panel1.Visible = false;
panel2.Visible = false;
panel1.Visible = true;
panel1.Location = new Point(0, 0);
}
private void button1_Click(object sender, EventArgs e)
{

panel1.Visible = false;
panel2.Location = new Point(0, 0);
panel2.Visible = true;

}
private void button2_Click(object sender, EventArgs e)
{
MessageBox.Show("2");

}
Sunny_Kumar_ 5-Nov-12 6:56am    
sure, send it to me @ ebayermailid@gmail.com
by ignoring queued mouse events. i got my answer.

@everybody: thank you every one for your suggestions.
 
Share this answer
 
rearrange your both panel positions ...
 
Share this answer
 
Comments
neeraj@max 21-Nov-12 1:51am    
i alredy did that but it is not workng...

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900