I want to make my textbox to be able to receive multiline text from paste function and change it to single line as example below:
i want to change
this multiline text
just into single line.
please help
into
i want to change this multiline text just into single line. please help
I try to change the textmode to singleline but it end up just take the first line only. How can i do this? Below is my code. Many thanks!
<asp:Textbox id="Textbox" TextMode="MultiLine" CssClass="LongTextBox" Width="370px" Runat="server" AutoCompleteType="Disabled" autocomplete="off" AutoPostBack="true"></asp:Textbox>
You can replace the line breaks with a space.
string value = Textbox1.Text.Replace("\r\n", " ");
But if the text already contained a space before or after the line break, you'll get 2 spaces.
i want to change
this multiline text
just into single line.
please help
so you could also do this
string value = TextBox1.Text.Replace("\r\n", " ").Replace(" ", " ");
Related
Here I have a MaskedEditExtender, with a validator using a regex.
It validates phone numbers with 8 or 9 digits:
<asp:TextBox Style="width: 135px" ID="txtTelefone" runat="server"></asp:TextBox>
<ajaxToolkit:MaskedEditExtender
ID="MaskedEditExtender_Telefone"
TargetControlID="txtTelefone"
runat="server"
Mask="\(99\)9999NN9999"
OnInvalidCssClass="txt-TextBox-Error"
ValidateRequestMode="Enabled"
ErrorTooltipEnabled="True"
Filtered="-"
PromptCharacter=" "
ClearMaskOnLostFocus="false"/>
<ajaxToolkit:MaskedEditValidator
ID="MaskedEditValidator_Telefone"
runat="server"
ControlExtender="MaskedEditExtender_Telefone"
ControlToValidate="txtTelefone"
ValidationExpression="^\(\d\d\)\d\d\d\d+-\d\d\d\d$"
Display="Dynamic"></ajaxToolkit:MaskedEditValidator>
The issue is: as you can see in the regex, the user can put 4 or 5 digits between the ')' and the '-'.
But the "Mask" field doesn't allow it.
I need the MaskedEditExtender to stop crying when I don't type all the characters, because they're not necessary. All I need to validate my field is the regex.
The MaskedEditExtender is there only to give a mask that allows me to type only numbers and have a (99) in the beggining. It does not need to validate anything.
Well, seems like there's no such functionality in MaskedEditExtender that allows you to put less than the characters in the mask, so I did a small workaround:
I've put autocomplete in the mask, adapted the regex to accept an empty space in the end of the string and trimmed it everytime I wanted to use the TextBox's value.
In MaskedEditValidator:ValidationExpression="^\(\d{2}\)\d{4,5}-\d{4} *$"
In MaskedEditExtender:AutoComplete="true" AutoCompleteValue=""
In CodeBehind: txtTelefone.Text.Trim();
With this, all unfilled characters will be replaced as space in the end of the string, the regex will take care of the validation, and the Trim() will remove the spaces. Thus allowing you to make the Mask's length optional.
Set ClearMaskOnLostFocus="true" on MaskedEditExtender.
I have lot of aspx pages with textboxes and I am using VB.NET.
<asp:TextBox runat="server" ID="txtADHD" MaxLength="6"></asp:TextBox>
I am using an regular expression validator
ValidationExpression="^\d+$"
This only helps me when there is space between two numbers and not when there is just space.
(1 space 1) it regular expression is validated.
Space and then I enter 1 the regular expression is not fired.
Is there an easy way to avoid space or modify this regular expression?
If you only care about spaces, then you can use the String.Replace() method, like this:
Dim replacedString As String = txtADHD.Text.Replace(" ", String.Empty)
Note: This will not take out new lines, tabs, etc., but if you have single line text, then that should not be an issue.
"What's the reqular expression to check there is no white space in a string", the following pattern will work:
ValidationExpression="^[\S]*$"
This will find any string that only contains non-white space (spaces, new lines, tabs, etc).
I have a multi line text box like :
<asp:TextBox CssClass="txtform" ID="txtWhom" runat="server" Height="78px"
Rows="10" TextMode="MultiLine"></asp:TextBox>
say I write the following text in that text box :
Dear Sir,
General Manager,
HSBC.
when I take that text in a variable in the vb.net code behind... and send it to a crystal report to show ... only ... the first line is shown... in that case only "Dear Sir," is shown ... but I want all the text ....
What Can I do ?
Use "Can Grow" option for that text object in Crystal report.
=>Right Click -> Text Object
=>Select Format Object
=>Use Can grow option in the dialog box.
It enables for variable length fields to grow vertically in the report and word wrap automatically. A maximum number of lines can be set with this option to control rogue or large data elements.
I wonder if your entered string includes carriage return & line feed chars that Crystal is not dealing with properly. You may need to strip those out or replace them with correct characters that Crystal expects.
When I try and display text from an the InnerText from an XML element. I get something like this:
I need this spacing \r\n\r\n\r\second lot of spacing\r\n\r\nMore spacing\r\n\r\n
I know you can replace \r\n with <br> but is there no function that automatically takes the html for you and why does it use \r and \n? Many thanks.
You can use <pre> tag - it will show the text as-is like you see it in text editor:
For example:
<pre><%=MyText%></pre>
Better practice for ASP.NET is:
<pre id="myPlaceholder" runat="server"></pre>
Then assign its value from code behind:
myPlaceholder.InnerHtml = MyText;
As for your question "why does it use \r and \n" those are carriage return and line feed characters, aka newline characters - when you have such text:
line 1
line 2
Then code reading it will give: line1\nline2 or line1\r\nline2 depending on how it's stored exactly.
I have a master/detail scheme for editing an asp:GridView using an asp:DetailsView. One of my fields is for a phone number of type int64 (always 10 digits). I would like this field to always be displayed as (###)###-####. My issue is the first digit in the phone number is always truncated for my edit item field which I used a MaskedEditExtender to achieve the formatting.
Here is my EditItemTemplate for the details view:
<cc1:MaskedEditExtender TargetControlID="edtPROJ_Leader_Phone" Mask="(999)999-9999" runat="server" ClearMaskOnLostFocus="false" ClipboardEnabled="true" MaskType="Number" />
<asp:TextBox ID="edtPROJ_Leader_Phone" runat="server" Text='<%# Bind("PROJ_Leader_Phone") %>' ></asp:TextBox>
When my details view is displayed for editing, the text box displays(_23)456-7890 for the integer 1234567890. Also worth noting that if the property MaskType="Number" is removed, the textbox shows: (234)567-890_. I would of course have the textbox show (123)-546-67890 after binding.
Problem could be that you're not using "Escape Characters" for your "(", ")", and "-".
Might want to change your mask from
Mask="(999)999-9999"
to
Mask="\(999\)999\-9999"
According to the documentation, there is no "(", ")", or "-", so you may be telling it to do something unintended. From the section on masks...
/ - Date separator
: - Time separator
. - Decimal separator
, - Thousand separator
\ - Escape character
{ - Initial delimiter for repetition of masks
} - Final delimiter for repetition of masks
Examples
9999999 - Seven numeric characters
99/99 - Four numeric characters separated in the middle by a "/"
http://www.asp.net/ajaxlibrary/act_MaskedEdit.ashx
This issue appears to be a bug related to: http://www.codeplex.com/AjaxControlToolkit/WorkItem/View.aspx?WorkItemId=11819
I had the same issue, and what solved it for me was changing the MaskedEditExtender's property
"ClearMaskOnLostFocus" to True.
I had the same issue too, and :
Doing despecialisation in the mask like :
Mask="\(999\)999\-9999",
With ClearMaskOnLostFocus set to true.
Solved the problem.
Thanks for all.