如何使用WebBrowser通过c#将文本插入textarea [英] How to insert text into textarea through c# with WebBrowser
本文介绍了如何使用WebBrowser通过c#将文本插入textarea的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
hi;
如何通过带有Forms.WebBrowser的c#将文本插入textarea?
hi;
How to insert text into textarea through c# with Forms.WebBrowser?
<body contenteditable="true" class="cke_editable cke_editable_themed cke_contents_rtl cke_show_borders" spellcheck="false"><p></p></body>
例如:
doc.GetElementById("title").SetAttribute("Value", txtTitle.Text);
或:
or:
HtmlElement textArea = webBrowserBlog.Document.All["body"];
if (textArea != null)
{
textArea.InnerText = "This is a test";
}
推荐答案
请参阅下面的解决方案。
Default.aspx
See the solution below.
Default.aspx
<head runat="server">
<title></title>
<script type="text/javascript">
function SetValue(str) {
document.getElementById("foo").value = str; ;
}
</script>
</head>
<body>
<form id="form1" runat="server">
<div>
<textarea id="foo"></textarea>
<asp:Button Text="Click" ID="btn" runat="server" onclick="btn_Click" />
</div>
</form>
</body>
</html>
< br $> b $ b
Default.aspx.cs
Default.aspx.cs
protected void btn_Click(object sender, EventArgs e)
{
string str = "hello";
ScriptManager.RegisterStartupScript(Page, typeof(Page), "", "javascript:SetValue('"+str+"')", true);
}
我希望这会对你有帮助。
I hope this will help you.
这篇关于如何使用WebBrowser通过c#将文本插入textarea的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文