“Type” text in HTML textfield/textarea component with .NET
-
4. března 2012 0:05
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
Všechny reakce
-
4. března 2012 2:55
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
-
5. března 2012 8:27Moderátor
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
-
5. března 2012 9:37
hello
this is a winfom project, not asp.net
Thanks
Do you know we will see our dead loved one again? John 5:25
-
7. března 2012 8:57Moderátor
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
-
7. března 2012 9:07hi there...
please check this link on how to fire key events in winform
http://support.microsoft.com/kb/327823Peter Koueik
-
7. března 2012 13:34Hello, 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
-
8. března 2012 4:57Moderátor
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
-
8. března 2012 6:10that is for button clink not text typing
Do you know we will see our dead loved one again? John 5:25
-
8. března 2012 8:39Moderátor
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
-
13. března 2012 2:10Moderátor
Hi Oghenez,
How's it going? Do you have any updates about the previous issue?
Bob Shen [MSFT]
MSDN Community Support | Feedback to us
-
13. března 2012 8:06Hello, 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
-
13. března 2012 8:32To simulate keyboard events use the SendKeys class.
-
13. března 2012 22:01
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