“Type” text in HTML textfield/textarea component with .NET

Unanswered “Type” text in HTML textfield/textarea component with .NET

  • Sunday, March 04, 2012 12:05 AM
     
      Has Code
    I am trying to fill a web form from my .NET app using this code:
    currElement.SetAttribute("Value", "some value");
    But this just pastes the text in the web browser without firing any events. I need to fire three events in the appropriate order:

    Keydown, KeyUp, Keypress

    I already have these.

    currElement.RaiseEvent("onChange");

    currElement.RaiseEvent("onClick");


    But I need more help on those mentioned events. Can anyone help me please?

    Do you know we will see our dead loved one again? John 5:25

All Replies

  • Sunday, March 04, 2012 2:55 AM
     
     

    If you want to capture key stokes in IE then use Javascript like this one.

    http://wiki.asp.net/page.aspx/1207/capturing-key-strokes-and-doing-a-post-back/

    chanmm


    chanmm

  • Monday, March 05, 2012 8:27 AM
    Moderator
     
     

    Hi Oghenez,

    You'll need to post it in the dedicated ASP.Net Forum http://forums.asp.net for more efficient responses, where you can contact ASP.NET experts. Thanks.


    Bob Shen [MSFT]
    MSDN Community Support | Feedback to us

  • Monday, March 05, 2012 9:37 AM
     
     

    hello

    this is a winfom project, not asp.net

    Thanks


    Do you know we will see our dead loved one again? John 5:25

  • Wednesday, March 07, 2012 8:57 AM
    Moderator
     
     

    Hi Oghenez,

    Sorry for the misunderstanding. Could you provide more detailed information about this issue please?


    Bob Shen [MSFT]
    MSDN Community Support | Feedback to us

  • Wednesday, March 07, 2012 9:07 AM
     
     
    hi there...
    please check this link on how to fire key events in winform
    http://support.microsoft.com/kb/327823

    Peter Koueik

  • Wednesday, March 07, 2012 1:34 PM
     
     
    Hello, Am trying to simulate typing in the webbrowser control input and textarea, so a normal typing will fire the events i have just mentioned at the onset, instead of just settting the value of the control to the text thanks

    Do you know we will see our dead loved one again? John 5:25

  • Thursday, March 08, 2012 4:57 AM
    Moderator
     
      Has Code

    Hi Oghenez,

    If you want to simulate typing in the webbrowser control, you can try use getElementsByTagName method and HtmlElement.InvokeMember Method. You can try the sample below.

            void webBrowser1_DocumentCompleted(object sender, WebBrowserDocumentCompletedEventArgs e)
            {
                HtmlElementCollection col = webBrowser1.Document.GetElementsByTagName("a");
                foreach (HtmlElement el in col)
                {
                    if (el.InnerText == "Sign in")
                    {
                        el.InvokeMember("click");
                    }
                }
    
            }

    Have a nice day.

    Bob Shen [MSFT]
    MSDN Community Support | Feedback to us

  • Thursday, March 08, 2012 6:10 AM
     
     
    that is for button clink not text typing

    Do you know we will see our dead loved one again? John 5:25

  • Thursday, March 08, 2012 8:39 AM
    Moderator
     
      Has Code

    Hi Oghenez,

    If you want to populate fields in the webbrowser control, you can use the Document property of the WebBrowser control to access HTML DOM. You can try the sample below.

            void webBrowser1_DocumentCompleted(object sender, WebBrowserDocumentCompletedEventArgs e)
            {
                mshtml.IHTMLDocument2 doc = (IHTMLDocument2)webBrowser1.Document.DomDocument;
                mshtml.HTMLInputElement ele1 = (mshtml.HTMLInputElement)doc.all.item("username", 0);
                ele1.value = "test value";
             }
    Hope it can help you.

    Bob Shen [MSFT]
    MSDN Community Support | Feedback to us

  • Tuesday, March 13, 2012 2:10 AM
    Moderator
     
     

    Hi Oghenez,

    How's it going? Do you have any updates about the previous issue?


    Bob Shen [MSFT]
    MSDN Community Support | Feedback to us

  • Tuesday, March 13, 2012 8:06 AM
     
     
    Hello, first this does not simulate typing as i ask at first, Second it does not raise events keyup,keydown,and keypress as each letter is being set can you gibve more tips? where can i get Dom and Mshtml documantattion in chm format, i dont have vs help installed regards

    Do you know we will see our dead loved one again? John 5:25

  • Tuesday, March 13, 2012 8:32 AM
     
     
    To simulate keyboard events use the SendKeys class.
  • Tuesday, March 13, 2012 10:01 PM
     
     

    Hello,

    I found out that Sendkeys does not always work, it works some times , and at other times, does not do anything, so i quite using it

    Regards


    Do you know we will see our dead loved one again? John 5:25