473,671 Members | 2,568 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Getting the selected text of WebBrowser control dropdown box.

I have a WebBrowser control on a .net 2.0 winforms app. I load up a
page and want to get the selected entry of a dropdown.

I can get the element:

HtmlElement stationList = browser.Documen t.GetElementByI d("dropdownFacI D");

How do I know get the selected entry (the text, not the id).

Thanks.
May 21 '07 #1
11 20298

"Frank Rizzo" <no**@none.comw rote in message
news:uX******** ******@TK2MSFTN GP06.phx.gbl...
>I have a WebBrowser control on a .net 2.0 winforms app. I load up a page
and want to get the selected entry of a dropdown.

I can get the element:

HtmlElement stationList =
browser.Documen t.GetElementByI d("dropdownFacI D");

How do I know get the selected entry (the text, not the id).
browser.Documen t.GetElementByI d("dropdownFacI D").Value;

May 21 '07 #2
Mr. Arnold wrote:
>
"Frank Rizzo" <no**@none.comw rote in message
news:uX******** ******@TK2MSFTN GP06.phx.gbl...
>I have a WebBrowser control on a .net 2.0 winforms app. I load up a
page and want to get the selected entry of a dropdown.

I can get the element:

HtmlElement stationList =
browser.Docume nt.GetElementBy Id("dropdownFac ID");

How do I know get the selected entry (the text, not the id).
browser.Documen t.GetElementByI d("dropdownFacI D").Value;
There is no .Value on the return of the .GetElementById method.
May 22 '07 #3

"Frank Rizzo" <no**@none.comw rote in message
news:O1******** ******@TK2MSFTN GP04.phx.gbl...
Mr. Arnold wrote:
>>
"Frank Rizzo" <no**@none.comw rote in message
news:uX******* *******@TK2MSFT NGP06.phx.gbl.. .
>>I have a WebBrowser control on a .net 2.0 winforms app. I load up a
page and want to get the selected entry of a dropdown.

I can get the element:

HtmlElement stationList =
browser.Docum ent.GetElementB yId("dropdownFa cID");

How do I know get the selected entry (the text, not the id).
browser.Docume nt.GetElementBy Id("dropdownFac ID").Value;

There is no .Value on the return of the .GetElementById method.

I don't know about this Net method, but it's making a call to JavaScript.

Below is JavaScript

var myTextField = document.getEle mentById('myTex t');
if(myTextField. value != "")
alert("You entered: " + myTextField.val ue)
else
alert("Would you please enter some text?")}You can do this kind of JavaScript statement.

if (document.getEl ementById('myTe xt').value != "")

Maybe, you can post to a .NET Web solution specific NG to get more help.


May 22 '07 #4
Mr. Arnold wrote:
>
"Frank Rizzo" <no**@none.comw rote in message
news:O1******** ******@TK2MSFTN GP04.phx.gbl...
>Mr. Arnold wrote:
>>>
"Frank Rizzo" <no**@none.comw rote in message
news:uX****** ********@TK2MSF TNGP06.phx.gbl. ..
I have a WebBrowser control on a .net 2.0 winforms app. I load up a
page and want to get the selected entry of a dropdown.

I can get the element:

HtmlElemen t stationList =
browser.Docu ment.GetElement ById("dropdownF acID");

How do I know get the selected entry (the text, not the id).

browser.Docum ent.GetElementB yId("dropdownFa cID").Value;

There is no .Value on the return of the .GetElementById method.


I don't know about this Net method, but it's making a call to JavaScript.

Below is JavaScript

var myTextField = document.getEle mentById('myTex t');
if(myTextField. value != "")
alert("You entered: " + myTextField.val ue)
else
alert("Would you please enter some text?")}You can do this kind
of JavaScript statement.

if (document.getEl ementById('myTe xt').value != "")

Maybe, you can post to a .NET Web solution specific NG to get more help.
It's a winforms application and a WinForms WebBrowser control.
May 22 '07 #5

"Frank Rizzo" <no**@none.comw rote in message
news:%2******** ********@TK2MSF TNGP02.phx.gbl. ..
Mr. Arnold wrote:
>>
"Frank Rizzo" <no**@none.comw rote in message
news:O1******* *******@TK2MSFT NGP04.phx.gbl.. .
>>Mr. Arnold wrote:

"Frank Rizzo" <no**@none.comw rote in message
news:uX***** *********@TK2MS FTNGP06.phx.gbl ...
I have a WebBrowser control on a .net 2.0 winforms app. I load up a
page and want to get the selected entry of a dropdown.
>
I can get the element:
>
HtmlEleme nt stationList =
browser.Doc ument.GetElemen tById("dropdown FacID");
>
How do I know get the selected entry (the text, not the id).
>
browser.Docu ment.GetElement ById("dropdownF acID").Value;

There is no .Value on the return of the .GetElementById method.


I don't know about this Net method, but it's making a call to JavaScript.

Below is JavaScript

var myTextField = document.getEle mentById('myTex t');
if(myTextField. value != "")
alert("You entered: " + myTextField.val ue)
else
alert("Would you please enter some text?")}You can do this kind
of JavaScript statement.

if (document.getEl ementById('myTe xt').value != "")

Maybe, you can post to a .NET Web solution specific NG to get more help.

It's a winforms application and a WinForms WebBrowser control.
It's still making a call to JavaScript I believe. That getElementById
command is a JavaScript command and not a .NET command.

Even though it's a Winform using a WebBrowser control, who .NET is going to
make the call to do it is ASPscript or JavaScript, which are scripting
languages that work with a Web browser.


May 22 '07 #6
>
It's a winforms application and a WinForms WebBrowser control.
Don't hold me to it, but the link may hold your solution by using the
InnerText to get the Value.

http://www.codeproject.com/aspnet/Prevent_attacks.asp

May 22 '07 #7
Hi Frank,

Please try this code:

HtmlElement element = webBrowser1.Doc ument.GetElemen tById("Select1" );
object objElement = element.DomElem ent;
object objSelectedInde x =
objElement.GetT ype().InvokeMem ber("selectedIn dex",
BindingFlags.Ge tProperty, null, objElement, null);
int selectedIndex = (int) objSelectedInde x;
if (selectedIndex != -1)
{
MessageBox.Show (element.Childr en[selectedIndex].InnerText);
}
Hope this helps.
Sincerely,
Walter Wang (wa****@online. microsoft.com, remove 'online.')
Microsoft Online Community Support

=============== =============== =============== =====
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscripti...ult.aspx#notif
ications. If you are using Outlook Express, please make sure you clear the
check box "Tools/Options/Read: Get 300 headers at a time" to see your reply
promptly.

Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 1 business day is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions or complex
project analysis and dump analysis issues. Issues of this nature are best
handled working with a dedicated Microsoft Support Engineer by contacting
Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/subscripti...t/default.aspx.
=============== =============== =============== =====

This posting is provided "AS IS" with no warranties, and confers no rights.

May 22 '07 #8
Walter Wang [MSFT] wrote:
Hi Frank,

Please try this code:

HtmlElement element = webBrowser1.Doc ument.GetElemen tById("Select1" );
object objElement = element.DomElem ent;
object objSelectedInde x =
objElement.GetT ype().InvokeMem ber("selectedIn dex",
BindingFlags.Ge tProperty, null, objElement, null);
int selectedIndex = (int) objSelectedInde x;
if (selectedIndex != -1)
{
MessageBox.Show (element.Childr en[selectedIndex].InnerText);
}
Walter,

Thanks for the code, but it didn't work out, because the dropdown has
OPTGROUPs ( http://www.w3schools.com/tags/tag_optgroup.asp ). This is
something I haven't seen up to now, but the code above just does not
work when an optgroup is present. The messagebox shows the contents of
the entire optgroup.

I actually resolved the problem as follows:

HtmlElement element = webBrowser1.Doc ument.GetElemen tById("Select1" )
string selectedValue = element.GetAttr ibute("value");
string elementSource = element.OuterHt ml;

And then running regex
(?<=<OPTION value={0} selected>).*?(? =</OPTION>)
against the elementSource.

It's hacky but it works. If you have the code that works for an
optgroup, that would be great.

Regards
>

Hope this helps.
Sincerely,
Walter Wang (wa****@online. microsoft.com, remove 'online.')
Microsoft Online Community Support

=============== =============== =============== =====
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscripti...ult.aspx#notif
ications. If you are using Outlook Express, please make sure you clear the
check box "Tools/Options/Read: Get 300 headers at a time" to see your reply
promptly.

Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 1 business day is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions or complex
project analysis and dump analysis issues. Issues of this nature are best
handled working with a dedicated Microsoft Support Engineer by contacting
Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/subscripti...t/default.aspx.
=============== =============== =============== =====

This posting is provided "AS IS" with no warranties, and confers no rights.
May 22 '07 #9
Hi Frank,

Thanks for your update and sorry for my ignorance of the OPTGROUP element.

Please try following code, hopefully it should work for situations with or
without OPTGROUP:

HtmlElement element = webBrowser1.Doc ument.GetElemen tById("Select1" );
foreach(HtmlEle ment child in element.All)
{
if (child.GetAttri bute("tagName") == "OPTION")
{
if (child.GetAttri bute("selected" ) == "True")
{
MessageBox.Show (child.GetAttri bute("text"));
break;
}
}
}
Regards,
Walter Wang (wa****@online. microsoft.com, remove 'online.')
Microsoft Online Community Support

=============== =============== =============== =====
When responding to posts, please "Reply to Group" via your newsreader so
that others may learn and benefit from your issue.
=============== =============== =============== =====

This posting is provided "AS IS" with no warranties, and confers no rights.

May 23 '07 #10

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
1647
by: Kenneth | last post by:
Hi, I am implementing a VB program using webbrowser control. Whenever a user makes a selection on the webbrowser control, I will have to identify the location where this selected text resides in HTML. I can use document.selection.createrange.text to get the text but I can't find anything close for me to extract the HTML portion. Please kindly shed some lights if you have any solutions to this? Thanks in advance.
5
1961
by: Hassan Bassam | last post by:
I am having a problem. How can I get the selected text from a text editor. I am using ASP.NET and VB as language. Thanx
0
278
by: tshad | last post by:
How do you get the selected text of a dropdown box? Selectedvalue will get you the value and selectedindex will get you the position, but how do you get the text (it isn't selectedText). Thanks, Tom
1
3524
by: Mike Evans | last post by:
In a windows application we have a webbrowser control and we want to change the selected item of a select or combobox inside the webbrowser control. We know how to change the value of a textbox with the .innertext property but how to do the same with the select or combobox html control ? Thanks in advance -- Mike Evans
4
1579
by: afrinspray | last post by:
Is there a way to get the selected text inside a div, or other element? Mike
4
11999
by: Steve Richter | last post by:
I would like to build an HTML stream as a string and have the WebBrowser control render that HTML. Then on PostBack, or whatever it is called, I would like my code to be the one that receives what the WebBrowser control is sending. Effectively, my code would be the web server and the WebBrowser control would be the web client. All the examples I am seeing have the WebBrowser control being directed to a URL from which to get the HTML...
6
5847
by: yasodhai | last post by:
Hi, I used a dropdown control which is binded to a datagrid control. I passed the values to the dropdownlist from the database using a function as follows in the aspx itself. <asp:DropDownList ID="FldType_add" Runat="server" DataSource='< %#GetFieldType()%>' DataValueField="Type" DataTextField="Type" /> Oce the page is loaded all the values are added to the dropdown list. But when I thought of getting the selected value from the...
0
8483
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8927
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8676
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
6237
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
4227
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4416
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2819
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
2062
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1816
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.