Hi ilancof,
Please refer below sample.
HTML
<asp:ScriptManager runat="server" />
<asp:TextBox ID="Editor1" runat="server" Width="300" Height="200" />
<ajaxToolkit:HtmlEditorExtender runat="server" TargetControlID="Editor1">
</ajaxToolkit:HtmlEditorExtender>
<br />
<asp:Button Text="Save" runat="server" OnClick="OnSave" />
Code
C#
public bool RemoveLinhasVazias(string pTexto)
{
string[] pDelimiters = new string[] { "\n", "\r", "\n\r" };
string[] pLines = pTexto.Split(pDelimiters, StringSplitOptions.RemoveEmptyEntries);
string pResult = string.Join(Environment.NewLine, pLines);
pResult = StripHTML(pResult);
if (string.IsNullOrEmpty(pResult.Trim()))
{
return true;
}
else
{
return false;
}
}
public static string StripHTML(string input)
{
return System.Text.RegularExpressions.Regex.Replace(input, "<.*?>", String.Empty);
}
protected void OnSave(object sender, EventArgs e)
{
string pTexto;
pTexto = Editor1.Text.Trim();
if (RemoveLinhasVazias(pTexto))
{
ClientScript.RegisterStartupScript(this.GetType(), "", "alert('Empty');", true);
}
else if (!RemoveLinhasVazias(pTexto))
{
ClientScript.RegisterStartupScript(this.GetType(), "", "alert('Not empty');", true);
}
}
VB.Net
Public Function RemoveLinhasVazias(ByVal pTexto As String) As Boolean
Dim pDelimiters As String() = New String() {vbLf, vbCr, vbLf & vbCr}
Dim pLines As String() = pTexto.Split(pDelimiters, StringSplitOptions.RemoveEmptyEntries)
Dim pResult As String = String.Join(Environment.NewLine, pLines)
pResult = StripHTML(pResult)
If String.IsNullOrEmpty(pResult.Trim()) Then
Return True
Else
Return False
End If
End Function
Public Shared Function StripHTML(ByVal input As String) As String
Return System.Text.RegularExpressions.Regex.Replace(input, "<.*?>", String.Empty)
End Function
Protected Sub OnSave(ByVal sender As Object, ByVal e As EventArgs)
Dim pTexto As String
pTexto = Editor1.Text.Trim()
If RemoveLinhasVazias(pTexto) Then
ClientScript.RegisterStartupScript(Me.GetType(), "", "alert('Empty');", True)
ElseIf Not RemoveLinhasVazias(pTexto) Then
ClientScript.RegisterStartupScript(Me.GetType(), "", "alert('Not empty');", True)
End If
End Sub
Screenshot