Click here to Skip to main content
15,891,184 members
Please Sign up or sign in to vote.
2.00/5 (1 vote)
See more:
I am trying to insertion the records of user and editing their record on the same page . If my query string contains the userid and action text fetch the user records populate the textbox control and change the button text to update.

On button click check the button text if it is update fetch the textboxes texts and fire updation. But the problem is when i update the records in text box and click the button it is fetching the old records instead of the new entered updated record form the textboxes.

In My Index.aspx file
ASP.NET
<lable>UserName</lable> <asp:TextBox runat="server" ID="usernamebox"  CssClass="form-control"/>
 <lable>Email</lable> <asp:TextBox runat="server" ID="emailbox"  CssClass="form-control"/>


A table is also on the same page for showing details of users & and anchor tag to edit the record ie
ASP.NET
<asp:HyperLink NavigateUrl='<%# Eval("EmployeeID","~/SystemUserForms/Index.aspx?uid={0}&Action=Edit") %>' Text="Edit" runat="server" />



Here is My PageLoad in CodeBehind File

C#
 protected void Page_Load(object sender, EventArgs e) { 
    if (Request.QueryString["uno"]!=null && Request.QueryString["Action"]!=null)
    {
    
    string uid= Request.QueryString[0];
    string action = Request.QueryString[1];
    registerbtn.Text = "Update Records";//button control text changing
    CoreModel.Repository.SysUsers S=               CoreModel.Repository.UserRepository.getUserByID(Convert.ToInt32(uid));
    
    
    
    usernamebox.Text = S.UserName;
    emailbox.Text = S.email;
   
    }
    
    
}


asp:button control onclick handler is

C#
protected void  Register_Users(object sender, EventArgs e)
 {

     if (Page.IsValid)
      {
             if(registerbtn.Text="Insert"){
                     insert()
                   }else if(registerbtn.Text="Update")
                      {  
                        string un=usernamebox.Text 
                        string e=emailbox.Text 

                      /* here em getting the old values ie if after fetching records from database  the usertextbox  text is bob  and i updated to bob.smith but  usernamebox.text returning bob */
                         /// update will goes here updation()


                       }

       }

}
Posted
Updated 21-Mar-15 5:58am
v3
Comments
Arif H Shigri 21-Mar-15 11:59am    
i also have tried the viewstatemode="disable" but it has no affect on this issue
Wombaticus 21-Mar-15 12:11pm    
Page_Load is called before your Register_Users event handler. You need to understand page lifecycle, and in particular the IsPostBack event.
Arif H Shigri 21-Mar-15 12:15pm    
thnx @Wombaticus . :)
F-ES Sitecore 21-Mar-15 14:33pm    
Also it is two equal signs for comparison, not one

registerbtn.Text == "Insert"
ramyajaya 21-Mar-15 17:44pm    
The issue may be, your page load function is getting called even on button click and refreshes the value of button textboxes

To avoid this,set Initial values of text boxes inside this function
if (!IsPostback)
{

usernamebox.Text = S.UserName;
emailbox.Text = S.email;

}

Hope this solves your issue

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900