Solved

Check a radio button in the web browser control

Posted on 2010-09-24
10
2,985 Views
Last Modified: 2013-12-25
I am having trouble making to check a radio button in the web browser control. The HTML code is below with the 2 radio buttons/options.

                             <input type="radio" name="visibility" id="visibility" value="0" /> Yes
                              <input type="radio" name="visibility" value="1" checked="checked" /> No


USING: VB 2008
0
Comment
Question by:battleweb
  • 4
  • 4
  • 2
10 Comments
 
LVL 65

Expert Comment

by:rockiroads
ID: 33756336
Are you not making use of asp.net?

in html, to set a value checked surely you just specify checked?

 <input type="radio" name="visibility" value="1" checked /> No
0
 

Author Comment

by:battleweb
ID: 33756365
huh?

<input type="radio" name="visibility" id="visibility" value="0" /> Yes
<input type="radio" name="visibility" value="1" checked="checked" /> No

is part of the source for the web page, I am trying to change the radio button selected using Visual Basic 2008 remotely, I am not trying to alter the source for the page.
0
 
LVL 29

Expert Comment

by:nffvrxqgrcfqvvc
ID: 33756474
Try something like this...
WebBrowser1.Document.GetElementById("visibility").SetAttribute("checked", "1") '// Yes
WebBrowser1.Document.GetElementById("visibility").SetAttribute("checked", "0") '// No

Open in new window

0
Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

 
LVL 65

Expert Comment

by:rockiroads
ID: 33756600
ok, got confused. just a thought why would you be using a webbrower control. Is this on a application?
0
 

Author Comment

by:battleweb
ID: 33756637
eql1044 - that almost does it, but the code above can only check the first radio if it isn't already checked - this is kind of my problem, there are 2 radio buttons, both named "visibility" but each has a different value (the first is 0 and the second is 1) - how do I control both?
0
 

Author Comment

by:battleweb
ID: 33756642
rockiroads - yes, which is why VB 2008 is being used.
0
 
LVL 29

Accepted Solution

by:
nffvrxqgrcfqvvc earned 500 total points
ID: 33756734
Okay I see what your saying.. You will probrably need to get a collection of HtmlElements so you can play with both of them instead of it only returning the first one..
Here is my test example which seems to work but to be honest, I'm not sure if there is a better way of filtering the elements besides filtering by Input tag and checking for "visibility" name.

Public Class Form1
    Dim list As New List(Of HtmlElement)
    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        WebBrowser1.Navigate("C:\Users\username\Documents\test.html")
    End Sub

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        list.Clear()
        Dim hElemCol As HtmlElementCollection = WebBrowser1.Document.GetElementsByTagName("input")
        For Each elem As HtmlElement In hElemCol
            If elem.Name.Contains("visibility") Then
                list.Add(elem)
            End If
        Next
        Dim yes As HtmlElement = list.Item(0)
        Dim no As HtmlElement = list.Item(1)
        'yes.SetAttribute("checked", "1")
        'no.SetAttribute("checked", "0")
    End Sub
End Class

Open in new window

0
 

Author Closing Comment

by:battleweb
ID: 33756860
eql1044 - with just a little tweaking, that works for me...Thanks.
0
 
LVL 29

Expert Comment

by:nffvrxqgrcfqvvc
ID: 33758637
Yeah... Actually the filtering was right there in plain site I just missed it :(  If you haven't already I would change it to this..
Dim checkboxes As HtmlElementCollection = WebBrowser1.Document.GetElementsByTagName("input").GetElementsByName("visibility")
Debug.Print(checkboxes.Count)

Open in new window

0
 
LVL 29

Expert Comment

by:nffvrxqgrcfqvvc
ID: 33758651
LOL... plain *sight
0

Featured Post

Active Directory Webinar

We all know we need to protect and secure our privileges, but where to start? Join Experts Exchange and ManageEngine on Tuesday, April 11, 2017 10:00 AM PDT to learn how to track and secure privileged users in Active Directory.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Formula for calculating ROI on training 6 49
Returning a value from a class function to a partial view in MVC5 7 28
VB.Net. Reading xml value 6 30
Code enhancement 4 22
Most everyone who has done any programming in VB6 knows that you can do something in code like Debug.Print MyVar and that when the program runs from the IDE, the value of MyVar will be displayed in the Immediate Window. Less well known is Debug.Asse…
A long time ago (May 2011), I have written an article showing you how to create a DLL using Visual Studio 2005 to be hosted in SQL Server 2005. That was valid at that time and it is still valid if you are still using these versions. You can still re…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…

829 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question