Show data in texbox c #, edit and update?

1

This time I bring a little problem that is stinging me. It's about that I have a form of a web solution in c # with asp.net that I want to edit. The data I want to edit is a table called User made in Sql Server.

The data of a particular user I have been able to recover, I have even put in the form so that you can see what you want to change. But when I delete the text box to put a new datum and press update, it keeps the same values I had before I deleted them.

I have noticed that every time I press update the page is loaded again from the Load, which is where I recover the data. From what I see, that is the problem. I'm not very familiar with this language and that's why I've been struggling with this update section.

protected void Page_Load(object sender, EventArgs e)
    {
        idUsuario = actualizar.getId();
        Modificacion modificacion = new Modificacion();

        txtNombre.Text = modificacion.mostrarNombre(idUsuario.ToString());
        txtCorreo.Text = modificacion.mostrarCorreo(idUsuario.ToString());
        txtUsuario.Text = modificacion.mostrarUsuario(idUsuario.ToString());                

    }

The action that the update button produces is:

 protected void btnActualizar_Click(object sender, EventArgs e)
    {

        String nombre = txtNombre.Text;
        String correo = Convert.ToString(txtCorreo.Text);
        String user = Convert.ToString(txtUsuario.Text);
        String estado = listEstado.SelectedValue;


        Actualizacion actualizacion = new Actualizacion();

        if (estado.Equals("Activo"))
        {
            actualizacion.actualizarUsuario(idUsuario.ToString(), nombre, correo, user, "1");
        }
        else
        {
            actualizacion.actualizarUsuario(idUsuario.ToString(), nombre, correo, user,"2");
        }     
    }

In short, my goal is to show the user's data in the text boxes without, when I delete the data and write the new information, I continue adding the values that I found from the database. I would greatly appreciate the help of this community. Thanks.

    
asked by Angel Manuel Elias 16.04.2018 в 22:25
source

1 answer

3

Your page load is recovering the original data and deleting the information you sent.

When you invoke an event this refreshes your page and the page load is executed before your Onclick event,

To prevent this from happening you should check the property

Page.isPostback  

To prevent your code from repeating

if(!Page.isPostback)
{
 //tu codigo que solo se ejcutara una vez
}
    
answered by 16.04.2018 / 22:39
source