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

RadGrid Edit / Update validation problem

0 Answers 52 Views
Ajax
This is a migrated thread and some comments may be shown as answers.
Bob
Top achievements
Rank 1
Bob asked on 18 Aug 2017, 10:29 AM

I have this code in my C# code behind page:

protected void gvEmailRedirectMaint_UpdateCommand(object sender, Telerik.Web.UI.GridCommandEventArgs e)
        {
            GridEditableItem editItem = (GridEditableItem)e.Item;
            string ID = (editItem["ID"].Controls[0] as TextBox).Text;
            string RedirectEmailAddress = (editItem["RedirectEmailAddress"].Controls[0] as TextBox).Text;
            string ModifiedBy = userID;

            if ((e.Item is GridEditableItem) && (e.Item.IsInEditMode))
            {
                GridEditableItem edititem = (GridEditableItem)e.Item;
                Regex regex = new Regex(@"^[A-Za-z0-9](([_\.\-]?[a-zA-Z0-9]+)*)@([A-Za-z0-9]+)(([\.\-]?[a-zA-Z0-9]+)*)\.([A-Za-z]{2,})$");

                TextBox txtbx = (TextBox)edititem["RedirectEmailAddress"].Controls[0];
                txtbx.Width = Unit.Pixel(300);

                Label l1 = new Label();
                l1.Width = Unit.Pixel(300);

                Match match = regex.Match(txtbx.Text);

                if (match.Success)
                {
                    l1.Text = "";
                }
                else
                {
                    l1.Text = "Please enter a valid email address";
                }
            }

 

When the user clicks the Update icon, I want to display a message if the email address is not in the proper format.  I want the error message to display directly to the right of the email address textbox.  But I can't get this to work.  Can anyone help?  

No answers yet. Maybe you can help?

Tags
Ajax
Asked by
Bob
Top achievements
Rank 1
Share this question
or