Solved

How to change Textarea value in webbrowser control (VB2008)

Posted on 2011-02-18
10
1,690 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
Optimizing Cloud Backup for Low Bandwidth

With cloud storage prices going down a growing number of SMBs start to use it for backup storage. Unfortunately, business data volume rarely fits the average Internet speed. This article provides an overview of main Internet speed challenges and reveals backup best practices.

 

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

Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Help with adding DLL file in Windows project 20 40
location of a form 2 25
Help with error in Query 2 31
Need help Creating PowerShell Script 5 57
Whether you’re a college noob or a soon-to-be pro, these tips are sure to help you in your journey to becoming a programming ninja and stand out from the crowd.
FAQ pages provide a simple way for you to supply and for customers to find answers to the most common questions about your company. Here are six reasons why your company website should have a FAQ page
This tutorial covers a step-by-step guide to install VisualVM launcher in eclipse.
The goal of the video will be to teach the user the difference and consequence of passing data by value vs passing data by reference in C++. An example of passing data by value as well as an example of passing data by reference will be be given. Bot…

820 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