I have a RadGrid that I populate from my SQL database. I use the RadGrid1_ItemCreated event to set the textbox width presently and that works fine. Now I want to set a regular expression for the same textbox. It is a textbox that contains an email address. Here is my C# code:
protected void gvEmailRedirectMaint_ItemCreated(object sender, GridItemEventArgs e)
{
if ((e.Item is GridEditableItem) && (e.Item.IsInEditMode))
{
string myMsg;
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);
Match match = regex.Match(txtbx.Text);
if(match.Success)
myMsg = txtbx.Text + " is Valid";
else
myMsg = txtbx.Text + " is Invalid";
}
}
When I run this, it performs no editing. If I click the update button, it saves the email address even though it is not in the proper format. What am I doing wrong?