Text are wiped out in the textboxs

Hello, I have an application for resetting the passowrd. So far so good. There is a check box
<asp:CheckBox ID="chkForceChange" AutoPostBack="true" Checked="True" 
            runat="server"/>Force user to change password at next login:
&nbsp;</p>

Open in new window

If I topple it, the text in the text boxs are always wiped out.
My code:
public partial class ResetPassword : System.Web.UI.Page
    {
        string userName = "";
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!User.IsInRole("Admin"))
            {
                //If not an admin, send the user to the login page.
                FormsAuthentication.RedirectToLoginPage();
            }
            // retrieve the username from the querystring
            userName = this.Request.QueryString["UserName"];

           
            if (!this.IsPostBack)
            {
                MembershipUser user = Membership.GetUser(userName);
                lblUserName.Text = AntiXss.HtmlEncode(user.UserName);
                lblEmail.Text = AntiXss.HtmlEncode(user.Email);
                lblEmail.NavigateUrl = "mailto:" + AntiXss.UrlEncode(user.Email);
                lblRegistered.Text = AntiXss.HtmlEncode(user.CreationDate.ToString("f"));
                lblLastLogin.Text = AntiXss.HtmlEncode(user.LastLoginDate.ToString("f"));
                lblLastActivity.Text = AntiXss.HtmlEncode(user.LastActivityDate.ToString("f"));
                chkIsOnlineNow.Checked = user.IsOnline;
                SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["MembershipDB"].ConnectionString);
                con.Open();
                SqlCommand cmd = new SqlCommand();
                cmd.Connection = con;
                cmd.CommandText = "SELECT [last4SSN]  FROM [User_ExtraInfo] WHERE [UserID] = @UserID";
                string UserID = user.ProviderUserKey.ToString();
                cmd.Parameters.Add("@UserID", SqlDbType.VarChar).Value = UserID;
                DataTable dt = new DataTable();

                using (SqlDataAdapter da = new SqlDataAdapter(cmd))
                {
                    da.Fill(dt);
                }
                lblSSN.Text = dt.Rows[0]["last4SSN"].ToString();
            }
        }

        protected void btnResetPw_Click(object sender, EventArgs e)
        {
            string userName = this.Request.QueryString["UserName"];
            MembershipUser user = Membership.Providers["SqlMembershipProviderOther"].GetUser(userName,false);

            if (newPass.Text == confirmPass.Text && confirmPass.Text != null && confirmPass.Text.Length > 0)
            {

Open in new window

The two text box's name are newPass and confirmPass.
Please look at the picture:
 web
zhshqzycAsked:
Who is Participating?
 
DerSpinnerCommented:
The AutoPostBack property defines whether you want to post the value instantly if it is changed, which means whenever you check or uncheck your checkbox it will be posted to the server if the property is set "true".
I asume you're posting and saving the values of all of your controls (including the value of your checkbox) if you hit the "Reset Password" button and it's therefore not necessary to post the checkbox value on every change.
0
 
DerSpinnerCommented:
Set AutoPostBack="false" or remove the property if you don't need it explicitely.
0
 
Jesus RodriguezIT ManagerCommented:
Are you using AJAX or update panels for this?? The event for the Checkbox on checked Change will submit  a postback to the page and wipe out the text from the textbox
0
 
zhshqzycAuthor Commented:
If I remove the postback, can it guarantee the function of changing password at next login?
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.