Solved

How to change Textarea value in webbrowser control (VB2008)

Posted on 2011-02-18
10
1,655 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
  • 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
 

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
IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 

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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Today I had a very interesting conundrum that had to get solved quickly. Needless to say, it wasn't resolved quickly because when we needed it we were very rushed, but as soon as the conference call was over and I took a step back I saw the correct …
If you haven’t already, I encourage you to read the first article (http://www.experts-exchange.com/articles/18680/An-Introduction-to-R-Programming-and-R-Studio.html) in my series to gain a basic foundation of R and R Studio.  You will also find the …
The viewer will learn how to use the return statement in functions in C++. The video will also teach the user how to pass data to a function and have the function return data back for further processing.
The viewer will be introduced to the member functions push_back and pop_back of the vector class. The video will teach the difference between the two as well as how to use each one along with its functionality.

747 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now