简体   繁体   中英

How to get the text value from a textarea from a web browser control in C#

How can I get the text value from a textarea from a web browser control in C#. If I don't know the ID or the Name of the textarea?

  var element1 = webBrowser1.Document.GetElementsByTagName("textarea");
  foreach (HtmlElement el in element1) {
    //GET THE TEXT
  }

EDIT: <textarea name="message"></textarea>

How would I get the value?

你可以用这个

varelement1= Request.Form["textarea"]

This cannot be done entirely using LINQ but you could have an extension defined like this

static class ControlExtension
    {
        public static IEnumerable<Control> GetAllControls(this Control parent)
        {
            foreach (Control control in parent.Controls)
            {
                yield return control;
                foreach (Control descendant in control.GetAllControls())
                {
                    yield return descendant;
                }
            }
        }
    }

and call

var list = this.GetAllControls().OfType<TextArea>().ToList();

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM