Solved

How to change Textarea value in webbrowser control (VB2008)

Posted on 2011-02-18
10
1,667 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
[Webinar] Disaster Recovery and Cloud Management

Learn from Unigma and CloudBerry industry veterans which providers are best for certain use cases and how to lower cloud costs, how to grow your Managed Services practice in IaaS clouds, and how to utilize public cloud for Disaster Recovery

 

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

3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

Question has a verified solution.

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

Having just graduated from college and entered the workforce, I don’t find myself always using the tools and programs I grew accustomed to over the past four years. However, there is one program I continually find myself reverting back to…R.   So …
Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
The viewer will learn how to implement Singleton Design Pattern in Java.
This theoretical tutorial explains exceptions, reasons for exceptions, different categories of exception and exception hierarchy.

863 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

18 Experts available now in Live!

Get 1:1 Help Now