how can I avoid auto completion of a TexBox by pressing a Button without functions

0

I have a form that when filling the page, is filled with data, my idea is to replace the current data with the new ones, but doing some tests, and adding a Button without any operation, rewrites me again the fields, and whether it's empty or when I write inside the TexBox, but when I press the button it's completed again, I do not know if it's a browser theme or something I'm doing is wrong.

protected void btnModify_Click (object sender, EventArgs e) {

    }



<div class="input-field col s10">

     <asp:Button ID="btnModificar" CssClass="btn-large btn-block black center-block" runat="server" Text="Modificar" OnClick="btnModificar_Click" />
</div>

protected void Page_Load(object sender, EventArgs e)
    { 

if (Session ["login"]! = null)                 {                     User user = (User) Session ["login"];

                string nombreCompleto = usuario.nombreCompleto();
                Master.navSet.Text = "Bienvenido: " + nombreCompleto;
                Master.ocultarLi = Visible;

                txtUsuario.Text = usuario._usuario;
                txtNombre.Text = usuario._nombre;
                txtApellido.Text = usuario._apellido;
                txtRut.Text = usuario._rut;
                txtCorreo.Text = usuario._correo;
                txtContraseña.Text = usuario._contraseña;

            }
            else
            {
                Response.Redirect("login.aspx");
            }

}

    
asked by Javier Gallardo 11.11.2018 в 18:30
source

1 answer

0

When you click on the button and have an event assigned to the server, even if you do not execute code within btnModificar_Click , you are generating a Postback . Now, the problem should come in the Load . Surely you are loading your data there in the fields. What you should do is always verify that the code is executed only when the page is loaded for the first time and to avoid repeating these actions in a postback (It may happen that you need to repeat some). What we are going to do is use Page .IsPostBack Property to validate this.

Your load should be with the following structure:

private void Page_Load()
{
    if (!IsPostBack)
    {
        //Aquí voy a ejecutar todas las acciones 
        //que correspondan solo cuando se carga por primera  vez la pagina.
    }else{
           //Solo las acciones que correspondan a un postback
    }

    // El resto de las acciones que se deben ejecutar siempre.
}

I hope it serves you. Greetings!

    
answered by 11.11.2018 / 18:51
source