Hi,
I have a change password form, which I would like to check :
1.it shouldn't be empty or null
2.txtNewpassword.Text = txtConfimPassword.Text
How to write if statement for those conditions./
Thanks.
Loading
Know the answer? Post it. Somebody with the same question will find it here.
Answer a question in the forums and earn +20 SHARP for every answer.
See unanswered questions
DevSocialUpcoming · 3rd editionAI Agents ConferenceDec 1–3, 2026Live onlineFree to attend5days leftRegister
Satyapriya NayakRank #47 · 31.5K reputationPosted Apr 9, 2013, 5:54 PM EDT
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace Fetch_multi_in_combobox
{
public partial class Form3 : Form
{
public Form3()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
if (txtNewpassword.Text == "" || txtConfimPassword.Text == "")
{
MessageBox.Show("Please enter values");
return;
}
if (txtConfimPassword.Text != txtNewpassword.Text)
{
MessageBox.Show("confirm password not matching with new passsword");
txtConfimPassword.Focus();
return;
}
}
}
}
Shankar MRank #874 · 2.5K reputationPosted Apr 25, 2013, 12:01 AM EDT
You can use check for null or empty values using string.IsNullOrEmpty method of string class.
if(string.IsNullOrEmpty(txtNewpassword.Text))
{
MessageBox.Show("Please enter values");
return;
}
Jignesh TrivediRank #16 · 50.3K reputationPosted Apr 25, 2013, 2:24 AM EDT
hi,
try
string newPassword = txtNewpassword.Text;
string confirmPassword = txtConfimPassword.Text;
if (!string.IsNullOrEmpty(newPassword) && !string.IsNullOrEmpty(newPassword) && newPassword.Equals(confirmPassword))
{
//do change password.
}
else
{
//show the error.
}
hope this will help you.