Solved

How to change Textarea value in webbrowser control (VB2008)

Posted on 2011-02-18
10
1,707 Views
Last Modified: 2012-05-11
I need to add text to a textarea. The application language is in Visual Basic 2008, I am using the webbrowser control.


HTML:
tr><td colspan="2" style="padding-bottom:5px;"><hr style="width:100%;" /></td></tr> 
					<tr> 
						<td class="col-left">Short description:<br /><br /><i>(appears in search results)</i></td> 
						<td style="padding-bottom:5px;" class="translatable">		<div class="lang_1" style="display: block;float: left;"> 
								<textarea class="rte" cols="100" rows="10" id="description_short_1" name="description_short_1"></textarea> 
							</div>		<div class="lang_2" style="display: none;float: left;"> 
								<textarea class="rte" cols="100" rows="10" id="description_short_2" name="description_short_2"></textarea> 
							</div>		<div class="lang_3" style="display: none;float: left;"> 
								<textarea class="rte" cols="100" rows="10" id="description_short_3" name="description_short_3"></textarea> 
							</div>		</td> 
					</tr> 

Open in new window


I tried the following without success:

WB1.Document.GetElementById("description_short_1").InnerHtml = "TEST!!!!"

Open in new window

WB1.Document.GetElementById("description_short_1").OutterHtml = "TEST!!!!"

Open in new window

WB1.Document.All("description_short_1").InnerHtml = "test!!!"

Open in new window

WB1.Document.GetElementById("description_short_1").InnerHtml = "TEST!!!"

Open in new window

0
Comment
Question by:battleweb
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 6
  • 4
10 Comments
 
LVL 47

Expert Comment

by:Wayne Taylor (webtubbs)
ID: 34931134
Use the SetAttribute method....

WebBrowser1.Document.GetElementById("description_short_1").SetAttribute("value", "TEST!!!")

Open in new window


Wayne
0
 

Author Comment

by:battleweb
ID: 34931143
I tried it and it did not work.
0
 
LVL 47

Expert Comment

by:Wayne Taylor (webtubbs)
ID: 34931161
When are you trying to set the value? The document needs to be loaded before you can set the value.
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:battleweb
ID: 34931201
I am using it after the document has loaded, placed code in a button for testing on demand.
0
 
LVL 47

Expert Comment

by:Wayne Taylor (webtubbs)
ID: 34931221
Can you post more of your code? I'm not having any problems setting the value of the textbox.

The below code is from a simple form with a WebBrowser and Button control and it works fine.
Public Class Form1

    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Dim html = <table><tr><td colspan="2" style="padding-bottom:5px;"><hr style="width:100%;"/></td></tr>
                       <tr>
                           <td class="col-left">Short description:<br/><br/><i>(appears in search results)</i></td>
                           <td style="padding-bottom:5px;" class="translatable"><div class="lang_1" style="display: block;float: left;">
                               <textarea class="rte" cols="100" rows="10" id="description_short_1" name="description_short_1"></textarea>
                               </div><div class="lang_2" style="display: none;float: left;">
                                   <textarea class="rte" cols="100" rows="10" id="description_short_2" name="description_short_2"></textarea>
                               </div><div class="lang_3" style="display: none;float: left;">
                                   <textarea class="rte" cols="100" rows="10" id="description_short_3" name="description_short_3"></textarea>
                               </div></td>
                       </tr>
                   </table>
        WebBrowser1.DocumentText = html.ToString
    End Sub

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        WebBrowser1.Document.GetElementById("description_short_1").SetAttribute("value", "TEST!!!")
    End Sub

End Class

Open in new window


Wayne
0
 

Author Comment

by:battleweb
ID: 34931282
Are there particular components that would help? There is far too much code in the page (1,029 lines) and besides it would be too difficult to parse through it and mask revealing info about my site. I did run the page in chrome and noticed that there appear to be frames and javascript at work:
<iframe id="description_short_1_ifr" src='javascript:""' frameborder="0" style="width: 100%; height: auto; "></iframe>

Open in new window


I tried some simple code:
WB1.Document.GetElementById("description_short_1_ifr").OuterHtml = "<p><strong>test</strong></p>"

Open in new window

and it shortens the textarea to 1 line and adds the "test" text but ignores the html and also generates an javascript error when i try to manually edit it afterwards:

 textarea1.jpg
0
 

Author Comment

by:battleweb
ID: 34931322
Got some more info, it is using the Tinymce Editor - I need to know how I can set text inside that editor.
0
 
LVL 47

Expert Comment

by:Wayne Taylor (webtubbs)
ID: 34931599
That changes things greatly, but unfortunately I have no experience with the Tinymce editor, so am unable to help further.
0
 

Accepted Solution

by:
battleweb earned 0 total points
ID: 34931737
I managed to figure out a work around on my own, I'm closing this question.
0
 

Author Closing Comment

by:battleweb
ID: 34959299
I managed to figure out a work around on my own, I'm closing this question.
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
In this blog, I will share you some basic tips for content marketing and to rank your website on Google.
The goal of the tutorial is to teach the user how to use functions in C++. The video will cover how to define functions, how to call functions and how to create functions prototypes. Microsoft Visual C++ 2010 Express will be used as a text editor an…
The viewer will learn how to pass data into a function in C++. This is one step further in using functions. Instead of only printing text onto the console, the function will be able to perform calculations with argumentents given by the user.

739 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question