Get (altered) textarea content from webBrowser element in C# - c#

I've searched the web for 2 days now and am about to give up on this, but I'm soo close to the final solution... so you're my last hope. ;)
I have made a little C# application with Windows Forms GUI that uses a webBrowser element to display an HTML file with a TinyMCE editor embedded - this way I get a nice window with customizable editor functions I can use perfectly for my needs in this project.
I can set the textarea input for this editor window without problems thanks to this solution posted here on stackoverflow: https://stackoverflow.com/a/16322324/3498545
However I'm having big troubles reading text from this textarea. If I read the element by ID as shown (for setting content) in the solution above, I get the old text, as TinyMCE never really saves the changes.
But how do I get the input that my users will make in the textarea via TinyMCE? Is there some way to trigger a form send in HTML to get this input?
Thank you so much for you help!

Ok, to answer my own question (maybe others find this useful sometime later):
The changes of TinyMCE don't get written back to the textarea field in realtime, so I had to work around that. One solution would be to add something in the javascript header that writes every change back to the textarea immediately, however this caused problems for me as TinyMCE code clean up is not involved at this point.
My solution was to temporarily create a new file where the input of the TinyMCE field gets written directly into source code, which is a piece of cake to read back in C#.
The javascript code needed looks like this:
setup : function(editor){
editor.on('submit', function (){
tinymce.triggerSave();
document.writeln("<!DOCTYPE html><html><body><div id='content'>"+document.getElementById('textarea').value+"</div></body></html>")
document.close()
});
}
After that you can read the content in C# with the following code:
webBrowser.Document.GetElementById("content").InnerHtml
Now I can store HTML formatted code in my SQL database that can be managed and edited with a shiny interface. ;)

Related

Tinymce Prompt before paste to properties or not

Is it possible to ask before pasting to retain formats in Tinymce Editor? Few days back i found that demo in which on pasting any content in editor it was asking to retain formats on not. Now i am unable to find that Tinymce demo link. Need your help and assistance.
Take a look at the paste_preprocess setting.
You can use a regular javascript user dialog inside the function.
Depending on the user action you may remove whatever you like from the pasted content.

MarkdownDeep pre issue

I created a web page in ASP.NET 4.0.
I'm using MarkdownDeep library (http://www.toptensoftware.com/markdowndeep/) to convert some text to HTML.
I found an issue that I can't fix. I hope you can help me.
I have some kind of forum, a want to post some code into the comment and see the indentation.
In the markdown preview editor, the text looks good. I save the textarea content to a database I show in the page, and I looks good.
For example, I try show two element tags of html to see the indentation on the code.
If I see the code with Chrome Development Tools, I look this:
<pre><code><head>
<title>
</code></pre>
It shows like this:
Everything is fine. But, if I reload the page, it appears like this
<pre><code><head><title>
</code></pre>
And it shows like this:
What I'm doing is:
write some text in the textarea
save text to the database
bring text back from database
converting markdown to html with the Transform() method of MarkdownDeep
put the result to the a Label's Text property
I tried, converting markdown before saving to the database, but nothing changes.
Ok, I finally found the solution.
That code was in a page that have a masterpage. If I took away the masterpage, everything is fine.
I don't know why... but that issue dissapear.

Translating website to Arabic dynamically in C#

I am facing a pesky problem at the moment on a large website with multiple languages. On arrival at the website, it detects what country you are from and prompts you to confirm this. On confirmation, it swaps out the pages languages from the DB and displays the relevant language. This is done using jQuery. Now the problem is that Arabic reads rtl, so I need to either:
-- swap out the stylesheets for "rtl" version
or
-- change the HTML tag and include a "dir='rtl'" arrtribute
Now, I have tried both of these, with failures on both. When I view the page source, it still shows the old Css file or HTML tag without the "dir" attribute. Correct me if I'm wrong but I believe this to be due to the DOM not registering the new changes, as they have happened asynchronously via jQuery after the DOM has been instantiated.
After all that blah blah and tldr;
Is there not an easier way to swap out the text direction dynamically? If this is a DOM issue, how can I reload the DOM after the asynchronous callback?
I have been at this issue for hours now and have had very little luck on the interwebz.
Any and all help is welcome and greatly appreciated.
Kind Regards,
William Francis
EDIT:
After much investigation I found that the only way to truly work the Arabic way is with a post-back. Once the language has been selected you do a postback, then its just a simple process of changing the Stylesheet HREF attribute from code behind. There doesn't seem to be any form of JavaScript or jQuery that can change it without a post-back and still reflect the new Stylesheet. NOTE: you need to set the Stylesheet HREF on each post-back, i.e. through a master page. The Stylsheet changes do not persist across pages.
Here's a website that helped greatly and explains a whole lot on Stylesheet changes using JavaScript. sadly, it didn't work for me.
http://www.alistapart.com/articles/alternate/
There could be several things going on. I found this page to be very helpful when I was dealing with a similar thing, so I highly recommend it:
http://www.w3.org/International/tutorials/bidi-xhtml/
Also, if you aren't already doing so, use a tool like Firebug to examine the generated DOM after your AJAX has run to be sure you are seeing the altered state of the DOM and not the initial source of the page. It is possible to change the dir dynamically--you can use Firebug to add a new attribute to the HTML tag of this very page (set dir="rtl") to see it change dynamically. It could be some other element is overriding the direction, it could be that the AJAX changes aren't loading correctly, or other things. If you can post more of your code it would be helpful to give a better answer, but I hope this will help.

Imitating ViewState into WinForm's

If it's possible it would be a great thing.
So is there a way how to achieve somehow a ViewState behavior into a WinForm's Application.
Like if i have a Bunch of TextBoxes ,than uses types text into them ,TextBoxes should store Their Text ,Location ,Size etc. and on Next Application Startup they should Load their Content Text ,Location ,Size etc.
Further...every Control into every Form ,should store Their State somehow ,and on Load ,they should Load their Content and Other Properties like they where last time Application was running.
PS : If there is not any Library or already made Solution ,than please don't try to spend time writing Code ,because it's not Fear to ask you guy's for Code ,i need just Direction's and Ideas because i plan to achieve it by my-self.Down-Voter's please consider that!!!
Using my google-fu I found this on code project.
The guy's written some code that effectively serializes a form out to XML so you can load it back in again. Don't know if it would cope with forms with dynamic controls that perhaps aren't on the form when you load it back in again - but I'm sure you can tweak the code to do what you want.

Problems with drag'n'drop from IE

My question is really simple and I don't know whether I am missing something or it is simply not allowed. I am trying to accept any content that has been selected in IE and dragged onto my app. All events fire as they should, and I am starting to analyze the content that I have received and this is where the fun begins.
When I ask for e.Data.GetFormats() in the string array, I can see clearly Text, HTML Format and Rich Text Format amongst other types.
But when I try to e.Data.GetDataPresent("Text") it returns false. Funny enough, when I try e.Data.GetData("Text") I get null too. (Was expected though)
My question is, should I be using something different to handle dragged content from IE? Or simply I can't access the data because it is from Internet Zone?
I forgot to add so later edit: - this is a .NET 2.0 Windows app and not asp.net nor a website :)
Thank you
Use Javascript for handling such tasks, it is fully compatible with the standard browsers.
You may want to program your own jQuery plugin for drag and drop
Here is one for dragging table rows

Categories

Resources