This is a migrated thread and some comments may be shown as answers.

Help with invalid radTextBox

1 Answer 147 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
Bruno
Top achievements
Rank 1
Bruno asked on 02 Mar 2012, 02:40 PM
Hello everybody,
Heres my question, when a email field for example(with a expression regular) is invalid, i want appears the alert icon.
In a different way to tell, i want this alert icon(error) appears every time a field doesnt pass in a validation(being a expressiion regular or not).

How can i do that?
thnkz in advance
<td>
    <telerik:RadTextBox ID="txtEmail" runat="server">
    </telerik:RadTextBox>
    <asp:RegularExpressionValidator ID="emailValidator" runat="server" Display="Dynamic"
        ErrorMessage="*Email inválido!" CssClass="erro" ValidationExpression="^[\w\.\-]+@[a-zA-Z0-9\-]+(\.[a-zA-Z0-9\-]{1,})*(\.[a-zA-Z]{2,3}){1,2}$"
        ControlToValidate="txtEmail">
    </asp:RegularExpressionValidator>
    <asp:RequiredFieldValidator ID="Requiredfieldvalidator1" runat="server" Display="Dynamic"
        ControlToValidate="txtEmail" CssClass="erro" ErrorMessage="*Digite um Email!" />
</td>

1 Answer, 1 is accepted

Sort by
0
Richard
Top achievements
Rank 1
answered on 06 Mar 2012, 06:33 PM
Bruno:

You can use a standard asp.net validation summary control with the "showmessagebox" property set to "true". Then, you can replace the "generic" popup window with the Telerik RadAlert that contains an Alert Icon and takes your error message as an input string.

Here's a full sample page, that includes the required RadWindowManager, JavaScript function, and ValidationGroup components.

See this in action at http://screencast.com/t/kinPq4Iqlz3C

Default.aspx:
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Default.aspx.cs" Inherits="Default" %>
 
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
 
<head runat="server">
    <title></title>
    <telerik:RadStyleSheetManager id="RadStyleSheetManager1" runat="server" />
</head>
<body>
    <form id="form1" runat="server">
    <telerik:RadScriptManager ID="RadScriptManager1" runat="server">
        <Scripts>
            <%--Needed for JavaScript IntelliSense in VS2010--%>
            <%--For VS2008 replace RadScriptManager with ScriptManager--%>
            <asp:ScriptReference Assembly="Telerik.Web.UI" Name="Telerik.Web.UI.Common.Core.js" />
            <asp:ScriptReference Assembly="Telerik.Web.UI" Name="Telerik.Web.UI.Common.jQuery.js" />
            <asp:ScriptReference Assembly="Telerik.Web.UI" Name="Telerik.Web.UI.Common.jQueryInclude.js" />
        </Scripts>
    </telerik:RadScriptManager>
    <script type="text/javascript">
        window.alert = function (string) {
            radalert(string);
        
    </script>
    <telerik:RadAjaxManager ID="RadAjaxManager1" runat="server">
    </telerik:RadAjaxManager>
    <telerik:RadWindowManager ID="RadWindowManager1" Title="Error" runat="server">
    </telerik:RadWindowManager>
    <div>
        <telerik:RadTextBox ID="txtEmail" runat="server">
        </telerik:RadTextBox>
        <asp:ValidationSummary ID="ValidationSummary1" runat="server" ShowMessageBox="true"
            ShowSummary="false" ValidationGroup="Validation" EnableClientScript="true" />
        <asp:RegularExpressionValidator ID="emailValidator" runat="server" Display="Dynamic"
            ErrorMessage="*Email inválido!" CssClass="erro" ValidationExpression="^[\w\.\-]+@[a-zA-Z0-9\-]+(\.[a-zA-Z0-9\-]{1,})*(\.[a-zA-Z]{2,3}){1,2}$"
            ControlToValidate="txtEmail" ValidationGroup="Validation" SetFocusOnError="true">
    </asp:RegularExpressionValidator>
        <asp:RequiredFieldValidator ID="Requiredfieldvalidator1" runat="server" Display="Dynamic"
            ControlToValidate="txtEmail" CssClass="erro" ErrorMessage="*Digite um Email!"
            ValidationGroup="Validation" SetFocusOnError="true" />
        <br />
        <asp:Button ID="btnValidate" runat="server" Text="Validate Input" ValidationGroup="Validation" />
        <br />
    </div>
    </form>
</body>
</html>

Hope this helps!
Tags
General Discussions
Asked by
Bruno
Top achievements
Rank 1
Answers by
Richard
Top achievements
Rank 1
Share this question
or