TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
Answers
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Forums
Monthly Leaders
Forum guidelines
cheguri saikumar
NA
43
6.3k
validating textboxes
Nov 12 2018 9:18 AM
i want error icon when each and every textboxes are empty
For example if txtcompanyname is empty when i click on submit button
txtCompnayname textbox should pop up with message icon
please help me.
thanks in advance
private void btnSubmit_Click_1(object sender, EventArgs e)
{
{
string From = string.Empty;
string FromPWD = string.Empty;
string ToAddress = string.Empty;
string BCCAddress = string.Empty;
string Name = string.Empty;
string Phone = string.Empty;
string Email = string.Empty;
string Comments = string.Empty;
string ticket = string.Empty;
string MessageBody = string.Empty;
try
{
txtCompanyName.Focus();
string file2 = "test.txt";
FileInfo fiRead = new FileInfo(file2);
string input = string.Empty;
int num = 1;
if (fiRead.Exists)
{
input = File.ReadAllText(file2);
}
if (input != string.Empty)
{
num = Convert.ToInt32(input);
}
File.WriteAllText(file2, (num + 1).ToString());
{
MessageBox.Show(num.ToString(), "Your Ticket Number is");
txtticket.Text = num.ToString();
if (string.IsNullOrEmpty(txtCompanyName.Text.Trim()))
{
errorProvider1.SetError(txtCompanyName, "Name is required.");
}
else
{
errorProvider1.SetError(txtCompanyName, string.Empty);
errorProvider1.SetError(txtName, string.Empty);
errorProvider1.SetError(txtPhone, string.Empty);
errorProvider1.SetError(txtEmail, string.Empty);
errorProvider1.SetError(txtIssue, string.Empty);
errorProvider1.SetError(txtComments, string.Empty);
}
}
ConfirmLicenseManager objConfirmLicenseManager = new ConfirmLicenseManager();
DocSortResult getAllConfigValues = objConfirmLicenseManager.GetAllConfigValues();
if (getAllConfigValues.resultDS != null && getAllConfigValues.resultDS.Tables[0].Rows.Count > 0)
{
foreach (DataRow dr in getAllConfigValues.resultDS.Tables[0].Rows)
{
switch (Convert.ToString(dr["Config_Name"].ToString()).ToUpper())
{
case "FROMEMAIL":
From = (this.Decrypt(dr["Config_Value"].ToString()));
break;
case "FROMPASSWORD":
FromPWD = (this.Decrypt(dr["Config_Value"].ToString()));
break;
case "TOADDRESS":
ToAddress = dr["Config_Value"].ToString();
break;
case "BCCADDRESS":
BCCAddress = dr["Config_Value"].ToString();
break;
}
}
SmtpClient client = new SmtpClient("smtp.gmail.com");
client.Port = 587;
client.EnableSsl = true;
client.Timeout = 100000;
client.DeliveryMethod = SmtpDeliveryMethod.Network;
client.UseDefaultCredentials = false;
client.Credentials = new NetworkCredential(From, "");
MailMessage msg = new MailMessage();
msg.To.Add(ToAddress);
msg.Bcc.Add(BCCAddress);
msg.From = new MailAddress(From);
msg.Subject = "Application TicketScreen";
if (txtCompanyName.Text != "") CompanyName = txtCompanyName.Text.Trim();
if (txtName.Text != "") Name = txtName.Text.Trim();
if (txtPhone.Text != "") Phone = txtPhone.Text.Trim();
if (txtEmail.Text != "") Email = txtEmail.Text.Trim();
if (txtIssue.Text != "") Issue = txtIssue.Text.Trim();
if (txtComments.Text != "") Comments = txtComments.Text.Trim();
if (txtticket.Text != "") ticket = txtticket.Text.Trim();
{
}
string Message = "CompanyName: " + CompanyName + "\r\n" + "\r\n" + "Name: " + Name + "\r\n" + "\r\n" + "Phone: " + Phone + "\r\n" + "\r\n" + "Email: " + Email + "\r\n" + "\r\n" + "ticket: " + ticket + "\r\n" + "\r\n" + "Issue: " + Issue + "\r\n" + "\r\n" + "Comments: " + Comments;
msg.Body = Message;
//Attachment data = new Attachment(txtAttachments.Text);
//msg.Attachments.Add(data);
client.Send(msg);
TicketScreen objticketScreen = new TicketScreen();
}
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
txtCompanyName.Text = "";
txtName.Text = "";
txtPhone.Text = "";
txtEmail.Text = "";
txtComments.Text = "";
txtIssue.Text = "";
txtticket.Text = "";
this.Hide();
}
}
private readonly byte[] IVRegular = new byte[8] { 54, 17, 92, 36, 0, 18, 237, 152 };
public string Issue { get; private set; }
public string CompanyName { get; private set; }
private string Decrypt(string encryptedQueryString)
{
string EncryptionKey = "";
string methodName = "decrypt()";
try
{
byte[] buffer = null;
buffer = Convert.FromBase64String(encryptedQueryString);
TripleDESCryptoServiceProvider des = new TripleDESCryptoServiceProvider();
MD5CryptoServiceProvider MD5 = new MD5CryptoServiceProvider();
des.Key = MD5.ComputeHash(ASCIIEncoding.ASCII.GetBytes(System.Configuration.ConfigurationSettings.AppSettings["SecurityKey"]));
des.IV = IVRegular;
EncryptionKey = Encoding.ASCII.GetString(des.CreateDecryptor().TransformFinalBlock(buffer, 0, buffer.Length));
}
catch (CryptographicException)
{
return "Invalid credentials";
// throw e;
//MessageBox.Show("Invalid LicenseKey", "Invalid LicenseKey");
}
catch (FormatException)
{
return "Invalid credentials";
//throw excp;
//MessageBox.Show("Invalid LicenseKey", "Invalid LicenseKey");
}
return EncryptionKey;
}
private void txtPhone_KeyPress(object sender, KeyPressEventArgs e)
{
lblErrorMsg.Visible = false;
if ((e.KeyChar >= 48 && e.KeyChar <= 57) || e.KeyChar == 8)
{
e.Handled = false;
}
else
{
lblErrorMsg.Visible = true;
lblErrorMsg.Text = "Please enter numbers only";
e.Handled = true;
}
}
private void TicketScreen_Load(object sender, EventArgs e)
{
this.Hide();
}
private void label8_Click(object sender, EventArgs e)
{
}
Reply
Answers (
1
)
How to change the content of other computers by using one PC
Looking for help with creating my first C# MDI form software