1
  1. How can I get an HtmlElement if the source code doesn't have the "id=''", but only has the "name=''". Document.GetElementById() doesn't work, and Document.All[""] doesn't work (obviously, because there is no ID.

  2. How can I simulate a form post?

Question 1 is more important because I found it harder to search. Question 2 I think i can get with more searching.

John Saunders
  • 160,644
  • 26
  • 247
  • 397
Rudi
  • 13
  • 3
  • Could you please specify what this has to do with the webbrowser control? Also, _which_ webbrowser control? WinForms? And what does this have to do with asp.net? – John Saunders Apr 28 '10 at 01:32
  • It's occurred to me that maybe the reason none of the solutions to item 1 is working is because you're doing it on the server side. Is that correct? If so, I'd strongly suggest giving the control an id. It will save you much heartache. – Damovisa Apr 28 '10 at 01:33

4 Answers4

1

GetElementsByTagName could get you all of the tags that you are after, then you can look through the returned collection for the element you are after (if there is more then one).

This post shows how to submit the form element.

Community
  • 1
  • 1
Glenn
  • 1,169
  • 7
  • 14
0

You get the element by GetElementByName also.

Atul Yadav
  • 496
  • 7
  • 26
  • Actually `GetElementsByName` because the name attribute doesn't have to be unique. http://www.w3schools.com/jsref/met_doc_getelementsbyname.asp – Damovisa Apr 27 '10 at 06:48
0

1. You can use the document.getElementsByName. It returns an array with all the elements that has the specified name (as names doesn't have to be unique like id:s).

2. You can use the submit method of a form element to post it. The form can either be an existing form in the page, or be created on the fly when you need it.

You can also use the XmlHttpRequest object to make a post, if you want to take care of the response yourself instead of having it load as a document.

Guffa
  • 687,336
  • 108
  • 737
  • 1,005
0

There seems to be some confusion here, so I'll summarize:

On the document object, there are a number of methods you can use to locate an element:

  • document.getElementById('myid'); will return a single DOM element (if it exists) with an id attribute equal to myid.
  • document.getElementsByName('myname'); will return an array of DOM elements with a name attribute equal to myname.
  • document.getElementsByTagName('div'); will return an array of DOM elements with a matching tag - in this case, all divs in the document.

The case is important.

Does that clear things up?

This should work with all browsers provided you're not trying to get elements inside an iframe or something like that, but if you're having trouble with different browsers, I'd suggest using something like jQuery. It abstracts the browser differences from you so you can use the same syntax regardless of the browser being used.

Damovisa
  • 19,213
  • 14
  • 66
  • 88