Click here to Skip to main content
15,896,557 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
hi;

How to insert text into textarea through c# with Forms.WebBrowser?


XML
<body contenteditable="true" class="cke_editable cke_editable_themed cke_contents_rtl cke_show_borders" spellcheck="false"><p></p></body>


example :
C#
doc.GetElementById("title").SetAttribute("Value", txtTitle.Text);


or:
C#
HtmlElement textArea = webBrowserBlog.Document.All["body"];
if (textArea != null)
{
    textArea.InnerText = "This is a test";
}
Posted
Comments
BillWoodruff 30-Nov-14 17:41pm    
When you execute the second code example: do you get a non-null result for 'textArea ?
samadblaj 30-Nov-14 17:46pm    
I do not know.
Please check example
My code:
<body contenteditable="true" class="cke_editable cke_editable_themed cke_contents_rtl cke_show_borders" spellcheck="false"><p></p></body>

BillWoodruff 30-Nov-14 18:15pm    
If you have not tested this code, so you don't know whether you get non-null result, I can't help you.
samadblaj 30-Nov-14 18:19pm    
error in send :
HtmlElement textArea = webBrowserBlog.Document.All["cke_editable cke_editable_themed cke_contents_rtl cke_show_borders"];
if (textArea != null)
{
textArea.InnerText = "This is a test";
}
BillWoodruff 30-Nov-14 18:51pm    
I have no idea what "error in send" means. Put a break-point in your code and identify where the error occurs, and what the exact error message is.

1 solution

See the solution below.

Default.aspx
XML
<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>


Default.aspx.cs
C#
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.
 
Share this answer
 
Comments
samadblaj 1-Dec-14 3:21am    
Thank you
It can not.
My code under Windows.
Praveen Kumar Upadhyay 1-Dec-14 3:29am    
You mean Windows Application??
samadblaj 1-Dec-14 3:30am    
yes.......
send text in webbowser...
code textareay webbrowser :
<body contenteditable="true" class="cke_editable cke_editable_themed cke_contents_rtl cke_show_borders" spellcheck="false"><p></p></body>

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900