Click here to Skip to main content
15,898,134 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Dear sir,
I have used tab control which have 3 tab pages, I want to write the code for 3 tab pages on 3 common buttons which are outside the tab control.
The action buttons:
1) OK --> to save the data.
2) Cancel--> to cancellation of saving data.
3) Modify -- > to update the data.
Posted

1 solution

So do you mean that you want to use a common event handler for those three buttons? If that's true and you use Forms, you can wire the click event to the same handler. So something like:

C#
// for example in constructor
this.btnOk.Click += new EventHandler(CommonEventHanldlerForClick);
this.btnCancel.Click += new EventHandler(CommonEventHanldlerForClick);
this.btnModify.Click += new EventHandler(CommonEventHanldlerForClick);

C#
void CommonEventHanldlerForClick(object sender, EventArgs e) {
   // Code goes here
}


However, you would need to recognize each button based on the sender parameter. For that, you can use the Tag property. Define a proper Tag on each button and then in the event handler check the tag of the button that is the sender.

But... I don't quite see the benefit from this. If you want to do this because you have a lot of common code for each button, I would still use a separate event handlers. Each event handler would then call a common or multiple common methods to do the actual operations. These methods can reside on the window class or another class if appropriate. This way you wouldn't mix the user interface to the logic (again if the assumption about the common code was true :)).
 
Share this answer
 
Comments
tusharkaushik 22-May-12 13:44pm    
but sir! iwant to use 3 buttons for 3 tab pages.can u provide any link related to these problem.
Thanks in advance...
Wendelius 22-May-12 14:36pm    
If you wire the event handlers for those three buttons, the number of tabs doesn't matter. In the question you said that you need three common buttons for the tabs. Or do you mean that you have 3 buttons on each tab so 9 buttons?
tusharkaushik 22-May-12 23:20pm    
only 3 common buttons for 3 tabpages
Wendelius 23-May-12 0:12am    
Okay, so do you mean that youneed to know what is the active tab inside the button or what is the question at hand? I'm a bit confused so if you could explain with a small example
tusharkaushik 23-May-12 10:15am    
for example: if i click 1st tab page , the button should add details for the ist tab page, else if the 2nd tab page is open, then the button should add the details of the 2nd tab page.

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