title: Defining the click event for a Login control integrated button
body: <p>Gooday. I have a <strong>login</strong> control, <strong>with an integrated user textbox and login button</strong>. I did this little test to see how it works, and surprisingly, after doing this:</p>
  
  <pre><code>protected void LoginButton_Click(object sender, EventArgs e)
  {
              TextBox userTextBox = (TextBox)Login1.FindControl("UserName");
              userTextBox.Text = "You pressed the button";
  }
  </code></pre>
  
  <p>the userTextBox doesn't change to "You pressed the button". Why?
  Thanks. Anna</p>
  
  <p><strong>EDIT: Sure, here is the markup (most of it is generated automatically by the system when adding the Login control); you will notice a button  LoginButton integrated in the Login:</strong></p>
  
  <pre><code>&lt;asp:Content ID="Content1" ContentPlaceHolderID="head" runat="server"&gt;
  &lt;/asp:Content&gt;
  
  &lt;asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" runat="server"&gt;
  
  &lt;asp:Panel ID="searchPanel" runat="server" DefaultButton="login1$LoginButton"&gt;
      &lt;asp:Login ID="Login1" runat="server" 
      FailureText="Logarea a esuat. Reincercati!" LoginButtonText="Logati-va!" 
      PasswordLabelText="Parola:" 
      PasswordRequiredErrorMessage="Trebuie sa introduceti parola." 
      RememberMeText="Tine-ma minte!" TitleText="Logare" 
      UserNameLabelText="Nume de utilizator:" 
      UserNameRequiredErrorMessage="Trebuie sa introduceti numele de utilizator."&gt;
          &lt;LayoutTemplate&gt;
              &lt;table border="0" cellpadding="1" cellspacing="0" 
                  style="border-collapse:collapse;"&gt;
                  &lt;tr&gt;
                      &lt;td&gt;
                          &lt;table border="0" cellpadding="0"&gt;
                              &lt;tr&gt;
                                  &lt;td align="center" colspan="2"&gt;
                                      Logare&lt;/td&gt;
                              &lt;/tr&gt;
                              &lt;tr&gt;
                                  &lt;td align="right"&gt;
                                      &lt;asp:Label ID="UserNameLabel" runat="server" AssociatedControlID="UserName"&gt;Nume 
                                      de utilizator:&lt;/asp:Label&gt;
                                  &lt;/td&gt;
                                  .........
                              &lt;tr&gt;
                                  &lt;td align="right" colspan="2"&gt;
                                      &lt;asp:Button ID="LoginButton" runat="server" CommandName="Login" 
                                          Text="Logati-va!" ValidationGroup="Login1" /&gt;
                                  &lt;/td&gt;
                              &lt;/tr&gt;
                          &lt;/table&gt;
                      &lt;/td&gt;
                  &lt;/tr&gt;
              &lt;/table&gt;
          &lt;/LayoutTemplate&gt;
  &lt;/asp:Login&gt;
  &lt;/asp:Panel&gt;
  &lt;/asp:Content&gt;
  </code></pre>
  
  <p>The code-behind goes liek this:</p>
  
  <pre><code>namespace Cinemax
  {
      public partial class Login : System.Web.UI.Page
      {
          protected void Page_Load(object sender, EventArgs e)
          {
  
                          //userTextBox.Focus(); // this sets the focus on the username textbox when the page loads
              this.Title = CinemaxConfiguration.SiteName + ": Login";
  
  
          }
  
          protected void LoginButton_Click(object sender, EventArgs e)
          {
              TextBox userTextBox = (TextBox)Login1.FindControl("UserName");
              TextBox userPassword = (TextBox)Login1.FindControl("Password");
  
              //Button loginBtn = (Button)Login1.FindControl("LoginButton");
              userTextBox.Text = "You pressed me";
  
              if (User1.ConnAttempt(userTextBox.Text, userPassword.Text) == 1)
              {
                  Session["User"] = userTextBox.Text;
                  Response.Redirect("Catalog.aspx");
              }
              else
              {
  
              }
          }
      }
  }
  </code></pre>