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.
hrolsonsAsked:
Who is Participating?
 
tpaynCommented:
my apologies hrolsons you need a VB6 solution and i just jump in with InvokeMember .. i hang my head in shame.

I have created a test project quickly .. you misspelled the id in your example

Dim element        
        Set element = WebBrowser1.document.getElementById("ctl04_hypImage")
        If Not element Is Nothing Then
            element.Click
        End If

Open in new window

0
 
Ady FootSharePoint ConsultantCommented:
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
0
 
hrolsonsAuthor Commented:
I see that code is for .NET, would it work for VB6?
0
Ultimate Tool Kit for Technology Solution Provider

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy now.

 
Ady FootSharePoint ConsultantCommented:
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.  
0
 
liveaspankajCommented:
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

0
 
liveaspankajCommented:
sorry the codes went multiple times :)
0
 
hrolsonsAuthor Commented:
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?
0
 
aikimarkCommented:
@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.
0
 
tpaynCommented:
try WebBrowser2.Document.getElementById("ct104_hypImage").InvokeMember("click")
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.