Click here to Skip to main content
15,909,897 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
form1 is loginform, and form2 has button i want make this button is enabled false...

This is Code in login form:-

s = "select Role_id from Users where User_name = '" + txt_UserName.Text + "' and Password = '" + txt_Password.Text + "' and Role = 'User' ";
sdAdapter = new SqlDataAdapter(s, con);
dt = new DataTable();
sdAdapter.Fill(dt);
if (dt.Rows.Count == 1)
{
string s2 = " insert into LoginAndOutDate(user_name, Login_Date) ";
s2 = s2 + " values(@user_name, CURRENT_TIMESTAMP) ";

if (con.State == ConnectionState.Closed)
con.Open();

using (sCommand = new SqlCommand(s2, con))
{
sCommand.Parameters.AddWithValue("@user_name", txt_UserName.Text);
sCommand.ExecuteNonQuery();
}

if (con.State == ConnectionState.Open)
con.Close();

this.Hide();
FRM_Main frm = new FRM_Main(txt_UserName.Text);
frm.RefToFormLogin = this;
frm.Show();
txt_Password.Clear();

What I have tried:

How i make button is enabled = false from another form
Posted
Updated 20-Aug-16 0:04am
v2
Comments
Richard Deeming 20-Aug-16 8:09am    
Also, never store passwords in plain text. Only store a salted hash of the password, using a unique salt per record.

Secure Password Authentication Explained Simply[^]
Salted Password Hashing - Doing it Right[^]

1 solution

Easiest way is to add a second parameter to your form constructor:
C#
public FRM_Main(string userName, bool enableMyButton)
   {
   InitializeComponent();
   ...
   myButton.Enabled = enableMyButton;
   }
And then pass the appropriate value when you construct the form instance.
 
Share this answer
 
Comments
MahmoudOmar 20-Aug-16 6:13am    
How i pass this parameter to form login, because i do that but it's not working
OriginalGriff 20-Aug-16 6:22am    
Show exactly the code you used in the constructor and when you create the instance.
MahmoudOmar 20-Aug-16 6:24am    
thanks i found my error and it's working know :)
OriginalGriff 20-Aug-16 6:36am    
Excellent!

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900