how can HyperLink add a OnClick eventHandler?

Discussion in 'ASP .Net Web Controls' started by yesming2002, Jun 17, 2004.

  1. yesming2002

    yesming2002 Guest

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

    }
     
    yesming2002, Jun 17, 2004
    #1
    1. Advertising

  2. yesming2002

    Anachostic Guest

    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.
    > }
    >
    > }
     
    Anachostic, Jun 18, 2004
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. =?Utf-8?B?QWxlc3NhbmRybyBSb3NzaQ==?=

    Add an eventhandler on a button_click

    =?Utf-8?B?QWxlc3NhbmRybyBSb3NzaQ==?=, Feb 17, 2004, in forum: ASP .Net
    Replies:
    1
    Views:
    489
    Chris Jackson
    Feb 17, 2004
  2. Karl
    Replies:
    0
    Views:
    546
  3. Oscar
    Replies:
    6
    Views:
    21,526
    Eirik
    Jul 31, 2005
  4. SimonSimon

    Add EventHandler to AudioClip?

    SimonSimon, May 8, 2006, in forum: Java
    Replies:
    1
    Views:
    377
    Oliver Wong
    May 8, 2006
  5. Howto add eventhandler to web custom usercontrol?

    , May 16, 2006, in forum: ASP .Net Building Controls
    Replies:
    1
    Views:
    176
Loading...

Share This Page