3

Is there a way to take the value of a string and pass that to a textbox within a web page while using the webbrowser control?

3 Answers 3

10
HtmlDocument doc = this.webBrowser1.Document;
doc.GetElementById("myId").SetAttribute("Value", "someValue");

try this

Sign up to request clarification or add additional context in comments.

3 Comments

Thanks. Another tiny related question. How would I press a button within a webpage as well?
invoke click like this..webBrowser1.Document.GetElementById("myBtn").InvokeMember("click");
Whoops, meant to update this. I got it shortly after I asked. Thanks for all your help.
2

You can do something like this:

String newValue = "Sample Text";
HtmlElement txt = WebBrowser1.Document.GetElementById("ElementIdOnHtmlPage");
txt.SetAttribute("value",newValue);

Comments

1

You can do the browser automation in C# for WebBrowser control.

Here's the reference article explaining how you can do that.

http://www.codeproject.com/KB/cs/mshtml_automation.aspx

2 Comments

Note that this article is not discussing the built in Windows.Forms.WebBrowser control
Still however it is possible to use this approach with the standard WebBrowser control by casting the webBrowser .Docuemt.DomDocument property to mshtml.HtmlDocumentClass

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.