How to assign a UserControl with the methods of its parent page?

L

Liming

Hi,

I have a UserControl called it <pm:task> and it's in Page1.

inside <pm:task> user control, I have 3 buttons, "create task", "edit
task", "delete task".

now I want to assign this <pm:task> this way in Page1..

protected void Create_Task_Function(object sender, EventArgs e)
{
}
....
protected void Update_Task_Function(object sender, EventArgs e)
{
}
....
protected void Delete_Task_Function(object sender, EventArgs e)
{
}

<pm:task onCreateTask_Clicked="Create_Task_Function"
onEditTask_Clicked="Update_Task_Function"
onDeleteTask_Clicked="Delete_Task_Fucntion"
runat="server"
/>

How could I create the UserControl such that when the buttons are
clicked, it delegates to the approriate functions on Page1 that has
been assigned to it?

Thanks
 
L

Liming

Never mind I figured out. In case others wants to know...

Simply add

public event System.EventHandler CreateTask_Clicked;
public event System.EventHandler EditTask_Clicked;
public event System.EventHandler DeleteTask_Clicked;

to your user Control

and in your button click function, raise it.. for example

<asp:button id="CreateTask_Button" onClick="CreateTask" runat="server"
/>

protectec void CreateTask(object sender, EventArgs e)
{
if (this.CreateTask_Clicked!=null)
{
CreateTask_Clicked(this,e);
}
}

.... do the same thing for EditTaks and DeleteTask.


Hope this helps.
 

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,769
Messages
2,569,579
Members
45,053
Latest member
BrodieSola

Latest Threads

Top