Design this page with label1 (text: e-mail), textbox1, button1(text:register), label2.
Label2 is just for displaying error message (Invalid email address in red colour). protected void Page_Load(object sender, EventArgs e) { [Link] = false; } Set the visible of the label2 to false during run time. protected void Button1_Click(object sender, EventArgs e) { if (CheckEmail([Link])) { //process anything like inserting the email address in database. } else { [Link] = true; [Link] = [Link]; [Link] = "Inavalid email"; [Link] = ""; [Link](); } } Here CheckEmail is function name.
private bool CheckEmail(string EmailAddress) { string strPattern = "^([0-9a-zA-Z]([-.\\w]*[0-9a-zA-Z])*@([0-9a-zA-Z][-\\w]*[0-9a-zA-Z]\\.)+[azA-Z]{2,9})$"; if ([Link](EmailAddress, strPattern)) { return true; } return false; }
Complete coding: using System; using [Link];
using [Link]; using [Link]; using [Link]; using [Link]; using [Link]; using [Link]; using [Link]; using [Link]; using [Link]; using [Link]; public partial class MasterPage : [Link] { protected void Page_Load(object sender, EventArgs e) { [Link] = false; } protected void Button1_Click(object sender, EventArgs e) { if (CheckEmail([Link])) { //process anything like inserting the email address in database. } else { [Link] = true; [Link] = [Link]; [Link] = "Inavalid email"; [Link] = ""; [Link](); } } private bool CheckEmail(string EmailAddress) { string strPattern = "^([0-9a-zA-Z]([-.\\w]*[0-9a-zA-Z])*@([0-9a-zA-Z][-\\w]*[0-9a-zA-Z]\\.)+[azA-Z]{2,9})$"; if ([Link](EmailAddress, strPattern)) { return true; } return false; } }