コード例 #1
0
        protected void ButtonOk_Click(object sender, EventArgs e)
        {
            AccountManager accountManager = new AccountManager(ConfigurationManager.ConnectionStrings["XiahDb"].ConnectionString,
                ConfigurationManager.ConnectionStrings["XiahDb"].ProviderName);

            TextBox UsernameTextBox = LoginView.FindControl("UsernameTextBox") as TextBox;
            TextBox PasswordTextBox = LoginView.FindControl("PasswordTextBox") as TextBox;
            Label UsernameExistsLabel = LoginView.FindControl("UsernameExistsLabel") as Label;

            if (Page.IsValid)
            {
                try
                {
                    accountManager.InsertUser(UsernameTextBox.Text, PasswordTextBox.Text);
                    Response.Redirect("~/AccountCreated.aspx");
                }
                catch (SqlException)
                {
                    UsernameExistsLabel.Text = "Username exists, choose a different one.";
                }
            }
        }