how can HyperLink add a OnClick eventHandler?

Y

yesming2002

hi~~
System.Web.UI.WebControls.HyperLink doesn't supply the OnClick eventHandler.

i inherit the HyperLink class and want to add a OnClick event.But it dosen't work.

here is the code. THX for any reply!

public class MyLink:System.Web.UI.WebControls.HyperLink
{

public event System.EventHandler Click;

protected void OnClick(EventArgs e)
{
if(Click!=null) Click(this,e);

}

protected void Reset()
{
Click=null;
}
}


public class MyPage: System.Web.UI.Page
{

....

//in the Page_load
private void Page_Load(object sender, System.EventArgs e)
{
link=new MyLink();
link.Click+=new System.EventHandler(this.link_Click);
}

.....

void link_Click
{
//do something when link clicked.
}

}
 
A

Anachostic

That is not a Hyperlink. It is a LinkButton. Unless there is some specific need, use a Linkbutotn and handle the Click event.
 

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,768
Messages
2,569,575
Members
45,053
Latest member
billing-software

Latest Threads

Top