Search code examples
c#asp.nettelerikradtextbox

RadTextBox EmptyMessage and .Replace Equals Empty or With a Value?


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;
}

Solution

  • 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.