-
Jun 22nd, 2006, 08:01 PM
#1
Thread Starter
Fanatic Member
How to execute a click on a hyperlink using c#?
hello!
How to execute a click on a hyperlink control using c#?
thanks!
-
Jun 22nd, 2006, 09:32 PM
#2
Lively Member
Re: How to execute a click on a hyperlink using c#?
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#
-
Jun 23rd, 2006, 09:13 AM
#3
Thread Starter
Fanatic Member
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...
-
Jun 23rd, 2006, 10:01 AM
#4
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 10:05 AM.
-
Jun 23rd, 2006, 05:25 PM
#5
Thread Starter
Fanatic Member
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...
-
Jun 24th, 2006, 09:39 AM
#6
Lively Member
Re: How to execute a click on a hyperlink using c#?
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"
-
Jun 24th, 2006, 11:06 AM
#7
Re: How to execute a click on a hyperlink using c#?
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>");
-
Jun 24th, 2006, 09:11 PM
#8
Lively Member
Re: How to execute a click on a hyperlink using c#?
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.
-
Jul 1st, 2006, 11:32 AM
#9
Thread Starter
Fanatic Member
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#?
-
Jul 1st, 2006, 12:25 PM
#10
Re: How to execute a click on a hyperlink using c#?
That is C#. And it should execute automatically once the page loads.
-
Jul 1st, 2006, 12:29 PM
#11
Thread Starter
Fanatic Member
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?
-
Jul 1st, 2006, 01:06 PM
#12
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.
-
Jul 1st, 2006, 03:41 PM
#13
Thread Starter
Fanatic Member
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?
-
Jul 1st, 2006, 03:56 PM
#14
Re: How to execute a click on a hyperlink using c#?
Remove the <script> tags.
-
Jul 1st, 2006, 03:57 PM
#15
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|