Skip to content

Simulate ENTER-KEY in HTML-Form in C#?

Rene Braun

Asked Jun 12, 2015, 5:11 PM EDT1 answer
Share
LinkedInX
I want to start off with a picture:
 
 
 

Lets assume i do have that form in Visual C#.What i want to accomplish now is that i simulate a "PRESSED ENTER KEY" on my keyboard when im in the HTML-ELEMENT "textbox_name". I already tried it with SendKeys.Send("{ENTER}"); which has no effect. I successfully wrote a value into the Box like this:

TypeScript
public void putByClass(String className, String value)
{
    HtmlElementCollection links = webBrowser1.Document.All;

    foreach (HtmlElement link in links)
    {
        if (link.GetAttribute("className") == className)
        {
            link.SetAttribute("value", value);
        }
    }
}

putByClass("textbox_name_class", "John");

After the line link.SetAttribute("value", value); which puts the name "John" into the Box i want to press the "Enter"-Button on the Keyboard. Thank you very much in advance.

1 Answer

Know the answer? Post it. Somebody with the same question will find it here.

  • Manoj Bhoir
    0
    Hi,
     
    You can do this using jQuery.
     
    JavaScript
    Try this code :
    
    e = jQuery.Event("keypress")
    e.which = 13 //choose the one you want
        $("#textbox_name").keypress(function(){
         alert('keypress triggered')
        }).trigger(e)
     
    Check demo here : http://jsfiddle.net/3xTM2/
    0