I'm trying to put button controls onto a page through adding it to the placeholders contained within the designer. The buttons contained within the original form's placeholders work fine but the one's that are added after the button selection event don't work. The properties (ie text) work fine but the event associated with the button doesn't trigger.
using System; using System.Web.UI.WebControls; namespace WebTrial { public partial class Login : System.Web.UI.Page { Boolean SignUp = false; protected void Page_Load(object sender, EventArgs e) { SetUpControls(); } public void SetUpControls() { Button butSubmit = new Button(), butSignIn = new Button(), butSignUp = new Button(); butSignIn.ID = "butSignIn"; butSignUp.ID = "butSignUp"; butSubmit.Text = "SUBMIT"; butSubmit.Click += new EventHandler(butSubmit_Click); butSignIn.Text = "Sign In"; butSignIn.Click += new EventHandler(butSignIn_Click); butSignUp.Text = "Sign Up"; butSignUp.Click += new EventHandler(butSignUp_Click); if (!SignUp) { PlaceHolder1.Controls.Clear(); PlaceHolder2.Controls.Clear(); PlaceHolder1.Controls.Add(butSubmit); PlaceHolder2.Controls.Add(butSignUp); } else { PlaceHolder1.Controls.Clear(); PlaceHolder2.Controls.Clear(); PlaceHolder1.Controls.Add(butSubmit); PlaceHolder2.Controls.Add(butSignIn); } } protected void butSignIn_Click(object sender, EventArgs e) { System.Diagnostics.Debug.WriteLine("SignInHit"); //Text does not come through SignUp = false; SetUpControls(); } protected void butSignUp_Click(object sender, EventArgs e) { System.Diagnostics.Debug.WriteLine("SignUpHit"); //Text does come through SignUp = true; SetUpControls(); } protected void butSubmit_Click(object sender, EventArgs e) { System.Diagnostics.Debug.WriteLine("SubmitHit"); //Works on the Sign In view but not the Sign Up } } }
No comments:
Post a Comment