“Type” text in HTML textfield/textarea component with .NET
-
2012年3月4日 上午 12: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
所有回覆
-
2012年3月4日 上午 02: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
-
2012年3月5日 上午 08:27版主
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
-
2012年3月5日 上午 09: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
-
2012年3月7日 上午 08:57版主
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
-
2012年3月7日 上午 09:07hi there...
please check this link on how to fire key events in winform
http://support.microsoft.com/kb/327823Peter Koueik
-
2012年3月7日 下午 01: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
-
2012年3月8日 上午 04:57版主
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
-
2012年3月8日 上午 06:10that is for button clink not text typing
Do you know we will see our dead loved one again? John 5:25
-
2012年3月8日 上午 08:39版主
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
-
2012年3月13日 上午 02:10版主
Hi Oghenez,
How's it going? Do you have any updates about the previous issue?
Bob Shen [MSFT]
MSDN Community Support | Feedback to us
-
2012年3月13日 上午 08: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
-
2012年3月13日 上午 08:32To simulate keyboard events use the SendKeys class.
-
2012年3月13日 下午 10: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

