User control with "public" events

L

Lukas Kurka

Hi,

I would like to create user control which will provide OnClick and other
events. Something like

index.aspx
.....
<uc1:MyControl id="MyControl1" runat="server" OnClick="MyControl1_Clicked"
/>
.....

index.aspx.cs
protected void MyControl1_Clicked(object sender, EventArgs e)
{
}

How can I do this?

Thanks
Lukas
 
M

Masudur

Lukas said:
Hi,

I would like to create user control which will provide OnClick and other
events. Something like

index.aspx
....
<uc1:MyControl id="MyControl1" runat="server" OnClick="MyControl1_Clicked"
/>
....

index.aspx.cs
protected void MyControl1_Clicked(object sender, EventArgs e)
{
}

How can I do this?

Thanks
Lukas

Hi ,
In your UserControl

public event EventHandler OnButtonClick;
protected void Button1_Click(object sender, EventArgs e)
{
if (OnButtonClick != null)
{
OnButtonClick(sender, e);
}
}

and in your page....

<uc2:Header ID="Header1" runat="server" OnButtonClick="Button1_Click"
/>

and in code behind of the page///

protected void Button1_Click(object sender, EventArgs e)
{
Response.Write("I am working");
}

Hope it help

Thanks

Masudur
Kaz Software Ltd.
www.kaz.com.bd
 
L

Lukas Kurka

Thats exactly what i was after, thx.

Do you happen to know how to add this to Properties window in Visual Studio?
For normal properties I just add [ Category("Appearence") ] but i doesn't
seem to work with events :(

Lukas
 

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,968
Messages
2,570,154
Members
46,702
Latest member
LukasConde

Latest Threads

Top