Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Winform RichTextBox 1

Status
Not open for further replies.

Sheco

Programmer
Jan 3, 2005
5,457
US
I am trying to determine the problem in an ASPX that I did not write. In fact, I do not yet have enough skill with ASP.NET to write this page so please go easy on me.

If the page were functioning properly, it would allow a user to edit the contents of a greeting letter in rich text format. From the user perspective, the page loads as a pure HTML <form>. The form contains an HTML TEXTAREA and a "Save" button.

The page properly loads the existing greeting letter contents into the TEXTAREA but when the form is submitted by clicking Save, an error appears.

I have emphasized the portions of the stack trace when seem to me to be the most interesting:[tt]
[Win32Exception (0x80004005): [red]Error creating window handle.[/red]]
System.Windows.Forms.NativeWindow.CreateHandle(CreateParams cp) +677
System.Windows.Forms.Control.CreateHandle() +213
System.Windows.Forms.Control.get_Handle() +60
System.Windows.Forms.Control.CreateHandle() +200
System.Windows.Forms.TextBoxBase.CreateHandle() +54
System.Windows.Forms.Control.get_Handle() +60
System.Windows.Forms.RichTextBox.ForceHandleCreate() +5
System.Windows.Forms.RichTextBox.set_SelectedText(String value) +13
[highlight] System.Windows.Forms.TextBoxBase.AppendText(String text) +105
FormLetterManagement.PersonalFormsBody.btnEditSave_Click(Object sender, EventArgs e)
[/highlight] System.Web.UI.WebControls.Button.OnClick(EventArgs e) +108
System.Web.UI.WebControls.Button.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String eventArgument) +57
System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl, String eventArgument) +18
System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData) +33
System.Web.UI.Page.ProcessRequestMain() +1292
[/tt]

The codebehind for the form Save button copies the submitted value of the TextArea into a WinForm rich textbox, appends a blank space character, and then saves the file. [red]*[/red] Below is the code that I believe is referenced by the stack trace:
Code:
Private Sub btnEditSave_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnEditSave.Click
        Dim filename As String
        filename = Label1.Text
        Dim temp As String = TextBox1.Text
        Dim richtextbox As New System.Windows.Forms.RichTextBox
        Dim newtext As String
        richtextbox.Text = temp
        Dim nfont As System.Drawing.Font
        richtextbox.Font = New System.Drawing.Font("Arial", 10)
        [highlight]richtextbox.AppendText(" ")[/highlight]
        newtext = richtextbox.Rtf

 [... snip ...]

I assume a RTB would be good for opening an existing letter in rich text format and converting it into plain text for use in an HTML TEXTAREA... but why would a RTB be used on the back side to process plain text submitted *from* a TEXTAREA? I can't imagine the users are submitting anything other than plain text because its not like these folks know any markup languages.

Why go through the effort to append a blank space character in Arial 10pt font? To insert some RTF markup code into an otherwise plaintext document?

Any insight will be very much appreciated.




[red]*[/red] Strangely, the file name is taken from a label, which although is displayed on the page, the value of the filename does not appear in any HTML form element so therefore must not be part of the submitted HTTP Request. I assume this is accomplished by the ASP.NET's mechanism for maintaining application state.
 
I forgot to mention that the ASPX source code declares the text editing control as:[tt]
<asp:TextBox id="TextBox1" runat="server" [...][/tt]


While ASP.NET renders this into HTML sent to the browser as follows:[tt]
<textarea name="TextBox1" id="TextBox1" [...][/tt]
 
I'm a bit confused as to why there is a System.Windows.Forms.RichTextBox control on the page as they are normally only used for desktop applications and I wouldn't expect them to work natively in a web environment (that's not to say they can't but it requires a lot of addiotnal work). Maybe you could substitute that control for a web based one? Do you know what logic is actually trying to be acheived here is is that also something else you have to guess?


-------------------------------------------------------

Mark,
[URL unfurl="true"]http://aspnetlibrary.com[/url]
[URL unfurl="true"]http://mdssolutions.co.uk[/url] - Delivering professional ASP.NET solutions
[URL unfurl="true"]http://weblogs.asp.net/marksmith[/url]
 
The RichTextBox is not on the page but its on the codebehind.

It appears the the purpose is to extract plain ASCII text from a rich text file.

I am not sure why it is used again when saving the file because, unless I misunderstand the logic, the only purpose when saving the file is to add a single Arial space character to an otherwise unformatted plain text string submitted from an HTML form via a TEXTAREA element. The new string and extra space are then pulled out of the RTF using the .RTF property and the resulting stream is saved to file... or at least thats how I read it.



 
After additional investigation, I'm beginning to wonder if this portion of the original project was ever actually completed.

Similar functionality elsewhere in the web app is achieved quite differently. Elsewhere, a fancy control named FreeTextBox is used to present the browser experience instead of a plain HTML TextArea element. (See:
Also elsewhere I see a third party library (ActiveUp) used to convert between RTF and HTML format... So I'm beginning to think this was used as a replacement for using the Winform control.
 
OK I guess I'll just write this one up as "never worked" and assume the "Error creating window handle" was caused by some failed attempt by the RichTextBox to interact with the desktop.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top