How to execute a click on a hyperlink using c#?-VBForums
Results 1 to 15 of 15

Thread: How to execute a click on a hyperlink using c#?

  1. #1

    Thread Starter
    Fanatic Member
    Join Date
    Aug 2000
    Location
    I'm right here!
    Posts
    849

    Question How to execute a click on a hyperlink using c#?

    hello!

    How to execute a click on a hyperlink control using c#?

    thanks!

    Dekel C.

  2. #2
    Lively Member SpagettiProg's Avatar
    Join Date
    Dec 2004
    Location
    Miami, Florida
    Posts
    82

    Re: How to execute a click on a hyperlink using c#?

    Quote Originally Posted by dekelc
    hello!

    How to execute a click on a hyperlink control using c#?

    thanks!

    Do you mean like simulate a human clicking on it? If that's the case, check out my tut on sending windows messages to other windows....


    http://www.vbforums.com/showthread.php?t=411426

    It has a video and the code is in VB, but I'm sure it will be easy to convert to C#
    If you feel my post has helped, please rate it
    http://www.silentthread.com

  3. #3

    Thread Starter
    Fanatic Member
    Join Date
    Aug 2000
    Location
    I'm right here!
    Posts
    849

    Re: How to execute a click on a hyperlink using c#?

    no... sorry... that is not what I meant...
    I meant that I have a hyperlink control on my asp.net web site.
    I want to use the c# code in my web site to execute a click on that
    hyperlink control...
    Dekel C.

  4. #4
    Frenzied Member Fishcake's Avatar
    Join Date
    Feb 2001
    Location
    Derby, UK
    Posts
    1,092

    Re: How to execute a click on a hyperlink using c#?

    So you want a hyperlink that when clicked instead of going to a specified URL executes some server side code?

    If that is the case you might want to use a <asp:LinkButton> instead as they have an onclick event.
    Last edited by Fishcake; Jun 23rd, 2006 at 11:05 AM.

  5. #5

    Thread Starter
    Fanatic Member
    Join Date
    Aug 2000
    Location
    I'm right here!
    Posts
    849

    Re: How to execute a click on a hyperlink using c#?

    actually, it's the other way around...
    I want to use a server side c# code to execute a click on one of my
    hyperlink control, because that control has features that the linkbutton
    control doesn't have... like a 'target' property...
    Dekel C.

  6. #6
    Lively Member SpagettiProg's Avatar
    Join Date
    Dec 2004
    Location
    Miami, Florida
    Posts
    82

    Re: How to execute a click on a hyperlink using c#?

    Quote Originally Posted by dekelc
    actually, it's the other way around...
    I want to use a server side c# code to execute a click on one of my
    hyperlink control, because that control has features that the linkbutton
    control doesn't have... like a 'target' property...
    Yes it does. Don't pay attention to the intellisense. Add this...

    target="_blank"
    If you feel my post has helped, please rate it
    http://www.silentthread.com

  7. #7
    ASP.NET Moderator mendhak's Avatar
    Join Date
    Feb 2002
    Location
    Ulaan Baator GooGoo: Frog
    Posts
    38,174

    Re: How to execute a click on a hyperlink using c#?

    Quote Originally Posted by dekelc
    actually, it's the other way around...
    I want to use a server side c# code to execute a click on one of my
    hyperlink control, because that control has features that the linkbutton
    control doesn't have... like a 'target' property...
    Page.RegisterStartupScript("doclick","<script language='JavaScript'>document.getElementById('hyperlinkid').click();</script>");

  8. #8
    Lively Member SpagettiProg's Avatar
    Join Date
    Dec 2004
    Location
    Miami, Florida
    Posts
    82

    Re: How to execute a click on a hyperlink using c#?

    Quote Originally Posted by mendhak
    Page.RegisterStartupScript("doclick","<script language='JavaScript'>document.getElementById('hyperlinkid').click();</script>");
    You are da man!

    I would rate you, but I need to spread them around a bit.
    I will remind myself.
    If you feel my post has helped, please rate it
    http://www.silentthread.com

  9. #9

    Thread Starter
    Fanatic Member
    Join Date
    Aug 2000
    Location
    I'm right here!
    Posts
    849

    Re: How to execute a click on a hyperlink using c#?

    hey mendhak, I am not so familiar with javascript.
    how do execute the 'doclick' event which you have defined, when working
    with c#?
    Dekel C.

  10. #10
    ASP.NET Moderator mendhak's Avatar
    Join Date
    Feb 2002
    Location
    Ulaan Baator GooGoo: Frog
    Posts
    38,174

    Re: How to execute a click on a hyperlink using c#?

    That is C#. And it should execute automatically once the page loads.

  11. #11

    Thread Starter
    Fanatic Member
    Join Date
    Aug 2000
    Location
    I'm right here!
    Posts
    849

    Re: How to execute a click on a hyperlink using c#?

    well, then how can I execute it on another time rather than the page load?
    just place it in the code where I want it?
    Dekel C.

  12. #12
    ASP.NET Moderator mendhak's Avatar
    Join Date
    Feb 2002
    Location
    Ulaan Baator GooGoo: Frog
    Posts
    38,174

    Re: How to execute a click on a hyperlink using c#?

    If you want it, say, on the button click event, then

    this.Button1.Attributes.Add("onClick","clickit();");

    Where clickit is a javascript function which does the clicking as shown above.

  13. #13

    Thread Starter
    Fanatic Member
    Join Date
    Aug 2000
    Location
    I'm right here!
    Posts
    849

    Re: How to execute a click on a hyperlink using c#?

    mendhak, so i've tried this:

    this.Button1.Attributes.Add("onClick", "<script language='JavaScript'>document.getElementById('HyperLink1').click();</script>");

    but it doesn't work.
    why?

    Dekel C.

  14. #14
    ASP.NET Moderator mendhak's Avatar
    Join Date
    Feb 2002
    Location
    Ulaan Baator GooGoo: Frog
    Posts
    38,174

    Re: How to execute a click on a hyperlink using c#?

    Remove the <script> tags.

  15. #15
    ASP.NET Moderator mendhak's Avatar
    Join Date
    Feb 2002
    Location
    Ulaan Baator GooGoo: Frog
    Posts
    38,174

    Re: How to execute a click on a hyperlink using c#?

    Your code didn't work because the code is adding javascript code to the onclick event of the button. Which means that it is not expecting an element tag, just javascript code.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Featured


Click Here to Expand Forum to Full Width

Survey posted by VBForums.