P
philipp
Hi
I want to write a customControl, which shows a login-component
containing textboxes for the username and password and a login-button.
As soon as a user logs in, the textboxes and the button disappear and a
new button for a logout appears. But it didn't work. I have to press
the button twice to change it from login to logout and vice verca.
Can anybody help me? Thanks in advance.
Philipp
Here is the code of my CustomControl
public class loginControl : Control, INamingContainer
{
private string text;
private TextBox username;
private TextBox password;
private TextBox loggedIn;
private Button b, b2;
[Bindable(true),
Category("Appearance"),
DefaultValue("")]
public string Text
{
get
{
return text;
}
set
{
text = value;
}
}
[Bindable(true),
Category("Appearance"),
DefaultValue("")]
public bool Login
{
get
{
this.EnsureChildControls();
if(loggedIn.Text=="")
{
return false;
}
return Convert.ToBoolean(loggedIn.Text);
}
set
{
this.EnsureChildControls();
loggedIn.Text=value.ToString();
//login = value;
}
}
protected override void CreateChildControls()
{
base.CreateChildControls ();
username=new TextBox();
password=new TextBox();
loggedIn=new TextBox();
loggedIn.Visible=false;
this.Controls.Add(loggedIn);
b=new Button();
b.Click += new EventHandler(this.loginBtn_Click);
b.Text="login";
b2=new Button();
b2.Click += new EventHandler(this.logoutBtn_Click);
b2.Text="logout";
if(!Login)
{
b2.Visible=false;
b.Visible=true;
}
else
{
b.Visible=false;
b2.Visible=true;
}
this.Controls.Add(username);
this.Controls.Add(password);
this.Controls.Add(b);
this.Controls.Add(b2);
}
private void loginBtn_Click(Object sender, EventArgs e)
{
this.Login=true;
}
private void logoutBtn_Click(Object sender, EventArgs e)
{
this.Login=false;
}
}
I want to write a customControl, which shows a login-component
containing textboxes for the username and password and a login-button.
As soon as a user logs in, the textboxes and the button disappear and a
new button for a logout appears. But it didn't work. I have to press
the button twice to change it from login to logout and vice verca.
Can anybody help me? Thanks in advance.
Philipp
Here is the code of my CustomControl
public class loginControl : Control, INamingContainer
{
private string text;
private TextBox username;
private TextBox password;
private TextBox loggedIn;
private Button b, b2;
[Bindable(true),
Category("Appearance"),
DefaultValue("")]
public string Text
{
get
{
return text;
}
set
{
text = value;
}
}
[Bindable(true),
Category("Appearance"),
DefaultValue("")]
public bool Login
{
get
{
this.EnsureChildControls();
if(loggedIn.Text=="")
{
return false;
}
return Convert.ToBoolean(loggedIn.Text);
}
set
{
this.EnsureChildControls();
loggedIn.Text=value.ToString();
//login = value;
}
}
protected override void CreateChildControls()
{
base.CreateChildControls ();
username=new TextBox();
password=new TextBox();
loggedIn=new TextBox();
loggedIn.Visible=false;
this.Controls.Add(loggedIn);
b=new Button();
b.Click += new EventHandler(this.loginBtn_Click);
b.Text="login";
b2=new Button();
b2.Click += new EventHandler(this.logoutBtn_Click);
b2.Text="logout";
if(!Login)
{
b2.Visible=false;
b.Visible=true;
}
else
{
b.Visible=false;
b2.Visible=true;
}
this.Controls.Add(username);
this.Controls.Add(password);
this.Controls.Add(b);
this.Controls.Add(b2);
}
private void loginBtn_Click(Object sender, EventArgs e)
{
this.Login=true;
}
private void logoutBtn_Click(Object sender, EventArgs e)
{
this.Login=false;
}
}