C
carentrica
For some reason, my "testButton_Click()" event handler is not being called
when testButton is clicked.
This Button and a Label are the only controls on a Web UserControl which is
loaded and displayed in the main document. When the button is clicked, a
postback occurs and the Page events get called, but not the Button Click
event.
public class LoginControl : System.Web.UI.UserControl
{
protected System.Web.UI.WebControls.Label Label1;
protected System.Web.UI.WebControls.Button testButton;
private bool loggedIn = false;
private void Page_Load(object sender, System.EventArgs e)
{
// Put user code to initialize the page here
if (Session["LoggedIn"] != null) {
loggedIn = (bool)Session["LoggedIn"];
}
}
private void testButton_Click(object sender, System.EventArgs e) {
// this event handler is never called!
loggedIn = true;
}
private void Page_PreRender(object sender, System.EventArgs e) {
defaultWebForm defaultPage = (defaultWebForm)Context.Handler;
// Method to switch the menu between "Log In" and "Log Out".
defaultPage.ShowLoggedIn(loggedIn);
}
private void Page_Unload(object sender, System.EventArgs e) {
Session["LoggedIn"] = loggedIn;
}
}
In the InitializeComponent method, the event is wired...
this.testButton.Click += new
System.EventHandler(this.testButton_Click);
Can anyone please tell me why?
when testButton is clicked.
This Button and a Label are the only controls on a Web UserControl which is
loaded and displayed in the main document. When the button is clicked, a
postback occurs and the Page events get called, but not the Button Click
event.
public class LoginControl : System.Web.UI.UserControl
{
protected System.Web.UI.WebControls.Label Label1;
protected System.Web.UI.WebControls.Button testButton;
private bool loggedIn = false;
private void Page_Load(object sender, System.EventArgs e)
{
// Put user code to initialize the page here
if (Session["LoggedIn"] != null) {
loggedIn = (bool)Session["LoggedIn"];
}
}
private void testButton_Click(object sender, System.EventArgs e) {
// this event handler is never called!
loggedIn = true;
}
private void Page_PreRender(object sender, System.EventArgs e) {
defaultWebForm defaultPage = (defaultWebForm)Context.Handler;
// Method to switch the menu between "Log In" and "Log Out".
defaultPage.ShowLoggedIn(loggedIn);
}
private void Page_Unload(object sender, System.EventArgs e) {
Session["LoggedIn"] = loggedIn;
}
}
In the InitializeComponent method, the event is wired...
this.testButton.Click += new
System.EventHandler(this.testButton_Click);
Can anyone please tell me why?