Click here to Skip to main content
16,016,678 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have a UserControl(UCPickList:-TextBox+Button+Label) in a project, using this project dll into another project, don't want to change the existing code. I just want to use this dll into my project and want to access Button_Click Event into my new project without using any other control on this form. I am unable to solve this issue from my side, i tried google but not satisfied.
Please suggest through logic/some source code.
Posted
Updated 28-May-13 17:45pm
v2
Comments
David_Wimbley 28-May-13 23:50pm    
Can't you just expose the Button Click Event Handler as public on your User Control. Then attach the click event within your code that calls the user control from DLL? Or is that too simple/im not getting something here.

Follow the steps:
Quote:
1. Create your own custom event in the user control.
2. Wire the Parent Page up to handle that event.

It's the same exact technique you are doing in the user control when you handle a button's click event. The code there isn't calling an event, it's wiring up the handler in the parent page.

See a similar answer Handle event of a User Control's control in a form[^]


--Amit
 
Share this answer
 
Comments
StackQ 29-May-13 0:47am    
yes, your solution is right.But i am trying to not to change the code of UC. Thanks for ur suggestion.
Try this
Control code
C#
public delegate void UCPickListHandler();
public event UCPickListHandler UCPickList_Click;

protected void Button_Click(object sender, EventArgs e)
{
    if (this.UCPickList_Click != null)
    {
       this.UCPickList_Click();
    } 
}

Page code

onUCPickList_Click event
C#
protected void UCPickList_Click()
{
 //your code
}
 
Share this answer
 

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