RadGrid Edit / Update validation problem

1 posts, 0 answers
  1. Bob
    Bob avatar
    15 posts
    Member since:
    Jun 2017

    Posted 18 Aug Link to this post

    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 = "";
                        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?  

Back to Top