updating/new textbox values

I have a form which has standard txt boxes.

The txt boxes currently display data which is pulled down from a sql server.
when i try and update the txt boxes with new values the old one get re-inserted.

I have used breakpoints to test my code and at no point do the new values get detected.

My code is below
// My code for the Page_Load
 
    protected void Page_Load(object sender, EventArgs e)
    {
        try
        {
            audit check_user_registration = new audit();
 
            check_user_registration.Logon_Name = WindowsIdentity.GetCurrent().Name.ToString();
            check_user_registration.Stored_Procedure_Name = "dbo.select_user";
            users = check_user_registration.select_user();
 
            //If it is the first time a user has logged onto the audit web page they will have to entre their details.
            //The details are entered using the web form and submitted via the submit_new_user button.
            //If they have visited the audit web page before their user details will appear in 
            //the same text boxes but the submit_new_user button will not be visible.
            if (users.Tables[0].Rows.Count == 0)
            {
                submit_new_user.Visible = true;
            }
            else
            {
                //loop through dataset and place user details in text boxes.
                foreach (DataRow theRow in users.Tables[0].Rows)
                {
                    FirstNameText.Text = theRow["FirstName"].ToString();
                    SurnameText.Text = theRow["SurName"].ToString();
                    TelText.Text = theRow["Telephone"].ToString();
                    EmailText.Text = theRow["Email"].ToString();
                    Directorate_Derpartment_ServiceText.Text = theRow["Directorate_Derpartment_Service"].ToString();
                }
                //Since user data is present, they are now given the chance to edit their details.
                edit_user_data_button.Visible = true;
            }
 
            check_user_registration.Logon_Name = WindowsIdentity.GetCurrent().Name.ToString();
            check_user_registration.Stored_Procedure_Name = "dbo.select_records";
            users = check_user_registration.select_records();           
 
            if(!Page.IsPostBack)
            {
            user_records.DataSource = users;
            user_records.DataBind();
            }
 
        }
        catch
        { 
        
        }
    }
 
 
//My code for the button 
protected void edit_user_data_button_Click(object sender, EventArgs e)
    {
       
            audit_update_personal_details update = new audit_update_personal_details();
            update.First_Name1 = FirstNameText.Text.ToString();
            update.Sur_Name1 = SurnameText.Text.ToString();
            update.Directorate_Derpartment_Service1 = Directorate_Derpartment_ServiceText.Text.ToString();
            update.Telephone1 = TelText.Text.ToString();
            update.Email1 = EmailText.Text.ToString();
            update.Logon_Name1 = WindowsIdentity.GetCurrent().Name.ToString();
 
            update.Stored_Procedure_Name = "dbo.update_personal_details";
            update.update_personal_details();
 
    }

Open in new window

Mr_ShawAsked:
Who is Participating?
 
Pratima PharandeConnect With a Mentor Commented:
Put your Page_Load code under Ispostback condition
0
 
Pratima PharandeCommented:
protected void Page_Load(object sender, EventArgs e)
    {
        try
        {
        if (!IsPostBack) {    
 audit check_user_registration = new audit();
 
            check_user_registration.Logon_Name = WindowsIdentity.GetCurrent().Name.ToString();
            check_user_registration.Stored_Procedure_Name = "dbo.select_user";
            users = check_user_registration.select_user();
 
            //If it is the first time a user has logged onto the audit web page they will have to entre their details.
            //The details are entered using the web form and submitted via the submit_new_user button.
            //If they have visited the audit web page before their user details will appear in
            //the same text boxes but the submit_new_user button will not be visible.
            if (users.Tables[0].Rows.Count == 0)
            {
                submit_new_user.Visible = true;
            }
            else
            {
                //loop through dataset and place user details in text boxes.
                foreach (DataRow theRow in users.Tables[0].Rows)
                {
                    FirstNameText.Text = theRow["FirstName"].ToString();
                    SurnameText.Text = theRow["SurName"].ToString();
                    TelText.Text = theRow["Telephone"].ToString();
                    EmailText.Text = theRow["Email"].ToString();
                    Directorate_Derpartment_ServiceText.Text = theRow["Directorate_Derpartment_Service"].ToString();
                }
                //Since user data is present, they are now given the chance to edit their details.
                edit_user_data_button.Visible = true;
            }
 
            check_user_registration.Logon_Name = WindowsIdentity.GetCurrent().Name.ToString();
            check_user_registration.Stored_Procedure_Name = "dbo.select_records";
            users = check_user_registration.select_records();          
 
            if(!Page.IsPostBack)
            {
            user_records.DataSource = users;
            user_records.DataBind();
            }
 }
        }
        catch
        {
       
        }

    }
0
 
Mr_ShawAuthor Commented:
thanks... u deserve a kiss  x
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.