hello!
How to execute a click on a hyperlink control using c#?
thanks!
:wave:
Printable View
hello!
How to execute a click on a hyperlink control using c#?
thanks!
:wave:
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....Quote:
Originally Posted by dekelc
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#
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...
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.
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...Quote:
Originally Posted by dekelc
target="_blank"
Page.RegisterStartupScript("doclick","<script language='JavaScript'>document.getElementById('hyperlinkid').click();</script>");Quote:
Originally Posted by dekelc
You are da man!Quote:
Originally Posted by mendhak
I would rate you, but I need to spread them around a bit. :(
I will remind myself.
hey mendhak, I am not so familiar with javascript.
how do execute the 'doclick' event which you have defined, when working
with c#?
That is C#. And it should execute automatically once the page loads.
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?
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.
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?
:wave:
Remove the <script> tags.
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.