[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

updating/new textbox values

Posted on 2008-11-07
3
Medium Priority
?
442 Views
Last Modified: 2013-12-17
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

0
Comment
Question by:Mr_Shaw
  • 2
3 Comments
 
LVL 39

Accepted Solution

by:
Pratima Pharande earned 2000 total points
ID: 22903611
Put your Page_Load code under Ispostback condition
0
 
LVL 39

Expert Comment

by:Pratima Pharande
ID: 22903622
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
 

Author Closing Comment

by:Mr_Shaw
ID: 31514297
thanks... u deserve a kiss  x
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Today I had a very interesting conundrum that had to get solved quickly. Needless to say, it wasn't resolved quickly because when we needed it we were very rushed, but as soon as the conference call was over and I took a step back I saw the correct …
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
Is your data getting by on basic protection measures? In today’s climate of debilitating malware and ransomware—like WannaCry—that may not be enough. You need to establish more than basics, like a recovery plan that protects both data and endpoints.…
As many of you are aware about Scanpst.exe utility which is owned by Microsoft itself to repair inaccessible or damaged PST files, but the question is do you really think Scanpst.exe is capable to repair all sorts of PST related corruption issues?
Suggested Courses
Course of the Month19 days, 13 hours left to enroll

872 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question