Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > ASP .Net Web Controls > how can HyperLink add a OnClick eventHandler?

Reply
Thread Tools

how can HyperLink add a OnClick eventHandler?

 
 
yesming2002
Guest
Posts: n/a
 
      06-17-2004
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.
}

}
 
Reply With Quote
 
 
 
 
Anachostic
Guest
Posts: n/a
 
      06-18-2004
That is not a Hyperlink. It is a LinkButton. Unless there is some specific need, use a Linkbutotn and handle the Click event.



"yesming2002" wrote:

> 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.
> }
>
> }

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Re: How include a large array? Edward A. Falk C Programming 1 04-04-2013 08:07 PM
How to add a hyperlink column to asp.net datagrid - where only one value is a hyperlink davetichenor ASP .Net 1 10-30-2006 02:57 PM
How to add a hyperlink column to asp.net datagrid - where only one value is a hyperlink Dave ASP .Net Datagrid Control 0 10-21-2006 07:48 PM
button.onclick = new Function("func2()") + button.onclick foldface@yahoo.co.uk Javascript 2 09-26-2005 08:13 AM
document.onclick=doIt() same as document.onclick=doIt ? bob Javascript 3 08-21-2003 12:14 PM



Advertisments