How do I convert asp:textbox to freetextbox - asp.net

I have an asp:TextBox that I need to convert to a FreeTextBox. The following is my asp:TextBox aspx code:
<%# Register TagPrefix="FTB" Namespace="FreeTextBoxControls" Assembly="FreeTextBox" %>
<asp:TextBox ID="tbxRiskDesc" runat="server" Width="90%" TextMode="MultiLine" Rows="6" onblur="Resize(this);" onkeypress="Resize(this);" ></asp:TextBox>
<rad:RadSpell ID="spellRiskDesc" runat="server" Width="5px" ControlToCheck="tbxRiskDesc" WordIgnoreOptions="UPPERCASE" FragmentIgnoreOptions="EmailAddresses,Urls" DictionaryLanguage="en-AU" SupportedLanguages="en-AU,English" AllowAddCustom="true" DictionaryPath="~/RadControls/Spell/TDF/" SpellCheckProvider="EditDistanceProvider" EditDistance="2" ButtonType="ImageButton" />
The following code is in the aspx.cs code:
Page_Load:
tbxRiskDesc.Attributes.Add("onchange", "setDirty();");
Reset_Data:
SetTextCurrentValue(tbxRiskDesc, dtEditTable, "RiskDesc");
Clear_Data:
SetTextValue(tbxRiskDesc, "RISK TITLE & DESC.:");
When I replace the "asp:TextBox" code in the aspx file with the following, the code behind has errors and i dont know how to change the code for the FreeTextBox for the Page_Load, Reset_Data & Clear_Data sections.
<FTB:FreeTextBox ID="tbxRiskDesc" runat="server"></FTB:FreeTextBox>
The reason for the change over is because we need to allow the users to put bullet points and hyperlinks into the text boxes.
All help is appreciated.

You have two options:
recommended: replace the textbox with RadEditor which has built-in integration with RadSpell
use the RadSpell API to spellcheck the FreeTextBox control: You have to get a reference to the body element of the iframe content area of FreeTextBox. After that you can implement a custom text source similarly as it is done for RadEditor in the following forum thread: Problem with spellcheck.
Using the RadEditor's get_contentAreaElement() method you can get a reference to RadEditor's iframe content area element and after that to get a reference to the body tag of the iframe:
var editorSource = $find('RadEditor1').get_contentAreaElement().contentWindow.document.body;
You should see in the FreeTextBox documentation or forums how to get a reference to the body element and update the above line in the provided in the forum article custom text source code.

Related

ASP.NET closing tag

When I use autocompletion in VisualStudio 2010 within my .aspx application, there are different default completions at closing control tags:
<asp:CheckBox />
<asp:Label></asp:Label>
Is there a explaination for this behaviour?
<asp:CheckBox></asp:CheckBox>
<asp:Label />
Wouldn't be invalid.
This is because ASP.NET's Label control is decorated with the ParseChildrenAttribute, with ParseChildren(false) while CheckBox isn't.
You can support the same behavior whith your custom controls, for example, with the following code, Visual Studio will behave like Label if you use MyControl in the web form editor:
[ParseChildren(false)]
public class MyControl : WebControl
{
...
}
The label closing is like that
<asp:Label runat="server"></asp:Label>
because usually we type something between
<asp:Label runat="server" ID="lblOne">better start programming now</asp:Label>
that is not the case for checkbox, that we type inside of it
<asp:CheckBox runat="server" Text="enable" ID="cbOne" />
We have on both elements the Text field, why on the one we prefer to write out side... Look at this example, on Label, or On other similar controls the text that we may have to write may include characters that are not allowed inside the Text Property, maybe a complex css style or what ever... The check box from the other side is only include a small text (yes, not, something like that)
<asp:Label ID="lblLabel" runat="server">
This is a <b>"label"</b>
<br />And one more line
</asp:Label>
and more example that compiles
<asp:Label ID="lblLabel" runat="server">
This is a <b>"label"</b>
<br />And one more line
<asp:Literal runat="server" ID="ltrOneMore">One more Control Inside</asp:Literal>
</asp:Label>
---but this is not compile--
<asp:Label ID="lblLabel2" runat="server"
Text="This is a <b>"label"</b>
<br /> and one more line"
/>
At the final end is a decision that the makes make - maybe we need to ask them for the real real reason.
Now this is also not compile
<asp:CheckBox runat="server" ID="cbMyChbx">one<asp:CheckBox>
check box when is render on page is use two controls, one input and one label, so they maybe need to help user to understand that the text is not going on the input control.
<asp:CheckBox />
Because the element has no content, you can close the tag with /> instead of using a separate closing tag
<asp:Label></asp:Label> or <asp:Label />
Displays static text on a Web Forms page and allows you to manipulate it programmatically.
Learn more about it Web Server Control
All the answers above are valid, but something additional. All the asp controls are eventually rendered as HTML controls and that also defines how the asp controls behave. For e.g. it is not necessary that text in a label is always set as
<asp:Label runat="server" ID="lblOne">better start programming now</asp:Label>
it can be also done as follows
<asp:Label runat="server" ID="lblOne" Text="better start programming"></asp:Label>
now both are correct format, so it is not valid to say that any control which needs content will have a separate closing tag. It also depends on how it rendered in HTML. for e.g by default asp Label is rendered as a span and doesnt conform to XHTML standards. Hope this makes it clear, always think of how it will be rendered and ASP tries to adhere to what eventually will be rendered.
cheers

How to set HtmlEditorExtender's content server-side

I'm using the AjaxControlToolkit's HtmlEditorExtender in my ASP.NET 4.0 web app:
<asp:TextBox ID="myTxt" runat="server" TextMode="MultiLine" Height="80px" Width="100%" />
<act:HtmlEditorExtender ID="heMyTxt" runat="server" TargetControlID="myTxt">
<Toolbar>
etc...
</Toolbar>
</act:HtmlEditorExtender>
When I set the content of the text box server-side like this:
myTxt.Text = htmlStringFromDatabase;
...the content in the textbox is the literal HTML markup (i.e. <b>Bold</b> shows up just like that, not like Bold). The formatting doesn't transfer, but the Extender does do its work on the textbox and set up its toolbar and buttons, etc. Is there a different way to set the content?
EDIT: turns out the HTML I get out of myTxt (the control that the extender is attached to) is encoded HTML. So now the question is how to stop the control from encoding its content. This problem is also presented in this question, but I'm not using LoadControl() or the designer to my page; I've written my markup manually.
Also, I don't know if this makes a difference, but I'm pulling the text out of the TextBox in the page's Page_Load handler.
Try to do like this,
myTxt.Text = HttpUtility.HtmlDecode(htmlStringFromDatabase);
I was able to solve this problem like this :
Literal lit = new Literal();
lit.Mode = LiteralMode.PassThrough;
lit.Text = HttpUtility.HtmlDecode(HTMLTExt);
TextBox1.Text = lit.Text; // The text box which HTMLEditorExtender is attached to

Multiline textbox - "Code blocks are not supported in this context"

I have a multiline (> 50 lines) textbox containing plain text. I want to add either a session variable to the text in this box. In asp I would have done it by putting in <% %> code blocks but in .net I am getting the following error: "Code blocks are not supported in this context". I assume therefore that this would need doing in code behind.
Is there a quicker way than putting all the text from the textbox in a string in code-behind and then adding the variable on like this? I would like to keep the text in my aspx page if possible.
Thanks
How about your codebehind does something like:
myTextbox.Text += Session ["mySessionVariable"];
after you've filled the textbox.
Incidentally, you don't have to
'put all the text from the textbox in
a string in codebehind'
as the .Net framework exposes all the front-end controls as codebehind objects automatically.
EDIT:
<asp:TextBox ID="TextBox1" runat="server" Rows="15" TextMode="MultiLine" Columns="70" Text='<%# Session["var1"] %>'></asp:TextBox>
This will work for binding just the session variable to the control. Don't forget to call
Page.DataBind();
after you've set your Session variables. Probably in Page_Load.
This will allow the binding such as it is, to occur. This won't work if you want to mix up static markup text with dynamic variables. For that, you'll need to get busy in the code-behind.
HTH.
Have you tried <%=Session["MySessionKey"] %> ?

Integrating MarkitUp and MarkdownSharp with asp.net forms website

I'm using markdownsharp with my asp.net forms website.
I want to use MarkItUp as my editor and have found a straight forward article on how to integrate with MVC which seems straight forward enough: http://rsolberg.com/2010/09/asp-net-mvc-markitup-rich-text-editor/
However, how do I do this with a forms website?
How do I get the MarkItDown Textarea on a postback and get the preview to work as well?
Place the Javascript and CSS file links in the head portion of the page just as you would with MVC. Then in your form, place a TextArea control. Set the rows and columns as needed.
<asp:TextBox ID="txtEditor" runat="server" TextMode="MultiLine" Columns="40" Rows="5" Text="" />
Then use JQuery to enable to functionality.
$(document).ready(function() {
$('<%=txtEditor.ClientID%>').markItUp(mySettings); });
Then on PostBack the contents of the editor will be available in the Text property of the TextBox control.
txtEditor.Text
This is not the only way to do this, you could also use a HTML TextArea control with a runat="server" attribute. Use whatever your personal preference is.

In an ASP control how can I get the text in a <Contentemplate> tag in the control code?

In my page ASP.net page I'm using a custom control like this:
<MyNamespace:MyControl runat="server" ID="myControl">
<contenttemplate>
This is the text I want to use
</contenttemplate>
</MyNamespace:MyControl>
In the c# code of the control how can I obtain a string containing the text between the <contentemplate> tag (eg. "This is the text I want to use") ?
Can you give me the code?
Thank you!
Check out How to make a templated control.

Resources