Link to home
Start Free TrialLog in
Avatar of hrolsons
hrolsonsFlag for United States of America

asked on

Click button on form using code

How can I click this button automatically:

<a id="ctl04_hypImage" href="folder.aspx?i=9262413" title="Files: 242 Size: 1656.4 MB Creation Date: 1/26/2011">
<img style="border-width:0px;" src="http://www.winkflash.com/photo/imagew3.aspx?i=436827807&c=9262413&z=0" title="Files: 242 Size: 1656.4 MB Creation Date: 1/26/2011">
</a>

I tried:

    WebBrowser2.Document.All.Item("ct104_hypImage").Click
    WebBrowser2.Document.getElementById("ct104_hypImage").Click

But neither worked.
Avatar of Ady Foot
Ady Foot
Flag of United Kingdom of Great Britain and Northern Ireland image

I think you're looking for .PerformClick.

http://msdn.microsoft.com/en-us/library/system.windows.forms.ibuttoncontrol.performclick.aspx

Let me know how you get on.

Ady
Avatar of hrolsons

ASKER

I see that code is for .NET, would it work for VB6?
Oh sorry - I thought you were using ASP.NET.  I've done some scouring and I'm not too sure you can achieve this in VB6.  I think that's probably why we now have PerformClick in .NET.

Hopefully someone else will come along and prove me wrong, otherwise I think you're out of luck.  
Add this in the head:

<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4/jquery.min.js"></script>
<script>
function clickbutton(){
$("#ctl04_hypImage").click();
}
</script>
 
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4/jquery.min.js"></script>
<script>
function clickbutton(){
$("#ctl04_hypImage").click();
}
</script>

Open in new window

You can call the javascript function clickbutton() any way you want. I have used a library called jquery.

You can see example and tutorials at:
http://docs.jquery.com/Tutorials:Live_Examples_of_jQuery
http://www.roseindia.net/ajax/jquery/ 
 
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4/jquery.min.js"></script>
<script>
function clickbutton(){
$("#ctl04_hypImage").click();
}
</script>

Open in new window

sorry the codes went multiple times :)
I must be in an alternate universe.  I asked a "Visual Basic" question in the "Visual Basic Classic" section and first answer I got was VB.NET and the next was JavaScript.

Does anyone have a Visual Basic 6.0 answer, please-o-please?
Avatar of aikimark
@hrolsons

I would have tried the same thing you tried.

If you don't get an answer in the next couple of days, please click the Request Attention link and ask for more expert eyes on this question.
Avatar of tpayn
tpayn

try WebBrowser2.Document.getElementById("ct104_hypImage").InvokeMember("click")
ASKER CERTIFIED SOLUTION
Avatar of tpayn
tpayn

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial