0

I have a RadTextBox control in my form, and in one of the methods, it sets the text of the control as such:

SecondHalfTB.EmptyMessage = sharedMailbox.MailboxEmail.Replace("CAAS_", string.Empty)
                                                 .Replace("@caas.gov.sg", string.Empty);

<td class="ms-formbody">
    CAAS_<telerik:RadTextBox ID="SecondHalfTB" runat="server" MaxLength="255">
    </telerik:RadTextBox>
    @caas.gov.sg
    <div>
        <asp:Label ID="lbSecondHalfTB" runat="server" CssClass="WarningMessage"></asp:Label>
    </div>
</td>

enter image description here


If I did not enter any values in the textbox, will the following statement return an empty string?

string newEmail = SecondHalfTB.Text;
if (newEmail == string.Empty)
{
    newEmail = SecondHalfTB.DisplayText;
}
gymcode
  • 4,431
  • 15
  • 72
  • 128

1 Answers1

0
CAAS_<telerik:RadTextBox ID="SecondHalfTB" runat="server" MaxLength="255">
</telerik:RadTextBox>
@caas.gov.sg

The values are actually hardcoded in your markup, aren't they? All you need is just remove them from the HTML.

By definition, the EmptyMessage property lets you specify the appearance of the input control when the user has not entered a value.

Whereas the DisplayText property allows you to set the display value from the Server to a different value the actual value. Similar to the empty message, but shown even if the input is not empty. This text will be cleared once the user changes the input value.

For you updated question - newEmail will be the same value as the DisplayText if the actual value of the textbox is empty.

woodykiddy
  • 6,074
  • 16
  • 59
  • 100
  • Hi @woodykiddy, thank you for your reply. Which means, if I don't enter any value in the textbox, `newEmail` will never be `null` as there will always be the value of `CAAS_` and `@caas.gov.sg`, am I right? – gymcode Jun 19 '19 at 05:15
  • My bad, lemme rephrase. Which means, `newEmail` will never be `empty` nor `null`, as it will take in the value of `DisplayText` if no inputs are detected in the tb, am I right? – gymcode Jun 19 '19 at 05:29
  • @gymcode - depends on whether or not if you enter values to the text box. Of course, if you leave it blank, then newEmail will get a value from DisplayText. – woodykiddy Jun 19 '19 at 11:17