Click here to Skip to main content
15,892,746 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi Guys this is the Login Page with the snipped:

C#
public int m = 0;
string user = Usernametxt.Text;
if (user.Equals("admin"))
{
    m = 1;
}
else { m = 0; }



and another snipped on another form where:

C#
private void HomePagefrm_Load(object sender, EventArgs e)
       {
           Loginfrm objLoginfrm = new Loginfrm();
           //int z=objLoginfrm.m;
           //int k=1;

           if (objLoginfrm.m==1)
           {

              Register_btn1.Enabled = true;
              Report_btn.Enabled = true;
           }
           else
           {

               Register_btn1.Enabled = false;
               Report_btn.Enabled = false;
           }
       }




However, when I run this code I get the buttons disabled for both admin and normal users.
Please Help
Posted
Updated 14-Mar-13 3:14am
v5
Comments
CHill60 14-Mar-13 8:12am    
According to your snippet you're never displaying objLoginForm so m is always it's initial value of 0. Not quite sure what the point of if(z.Equals(k))
what's wrong with if(objLoginfrm.m == 1?
Arora Varun 14-Mar-13 8:17am    
i even tried
if (objLoginfrm.m==1)
{

Register_btn1.Enabled = true;
Report_btn.Enabled = true;
}
but no...
[no name] 14-Mar-13 8:54am    
You are creating a new instance of LoginFrm so m will always be equal to 0.
Arora Varun 14-Mar-13 8:56am    
So what should be done in such a scenario...???
[no name] 14-Mar-13 9:00am    
Pass a reference to your login page to your homepagefrm.

You check for "Admin" but what if it was typed in as "admin", "ADMIN", "AdMiN" or any other combination?

According to the documentation for String.Equals: This method performs an ordinal (case-sensitive and culture-insensitive) comparison.

C#
public int m = 0;
string user = Usernametxt.Text.ToLower;  //Convert to all lower-case for comparison
if (user.Equals("admin"))
{
    m = 1;
}
else { m = 0; }


Also, don't you have to use ShowDialog to display the login form?

C#
Loginfrm objLoginfrm = new Loginfrm();
objLoginfrm.ShowDialog; // Show Login Form
//int z=objLoginfrm.m;
//int k=1;

if (objLoginfrm.m==1)
{
...
 
Share this answer
 
v2
Hi guys thanks finally i got an solution to the above query ..
wat i did was..

if (m == 1)
{
    HomePagefrm objForm3 = new HomePagefrm();
    objForm3.Show();
    objForm3.Register_btn1.Visible = true; //Register_btn1.Enabled = true;
    objForm3.Report_btn.Enabled = true;
    this.Hide();
}
else
{
    HomePagefrm objForm3 = new HomePagefrm();
    objForm3.Show();
    objForm3.Register_btn1.Enabled = false;
    objForm3.Report_btn.Enabled = false;
    this.Hide();
}


did it on log in page itself..
Phantom thanks fr your guidance...
 
Share this answer
 

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

  Print Answers RSS
Top Experts
Last 24hrsThis month


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