Use user input values in Asp.net c# webforms

Asked

Viewed 109 times

0

I created a form for the user to update the registration data. The user’s "old" data is stored in session variables that fill out the form as soon as the user clicks to update registration. The problem is that when saving the data in the database, the data entered by the session variables are considered instead of the new data entered in the form. Can you help me solve this? Thank you. Follow the code C#:

protected void btnEnviar_Click(object sender, EventArgs e)
    {
        MySqlConnection conexao = ConexaoDB.GetConexao();
        try
        {
            string comandoSQL = "UPDATE MA_USERS SET " +
            "nomecliente = '{1}', " +
            "facebook = '{2}', " +
            "website = '{3}', " +
            "cidade = '{4}', " +
            "estado = '{5}', " +
            "emailprofissional = '{6}' " +
            "where idcliente= '{0}'";

            comandoSQL = string.Format(comandoSQL, txtUsuario.Text, 
            txtNome.Text, txtFacebook.Text, txtWebsite.Text, txtLocal.Text, ddlEstado.Text, txtEmail.Text);
            Response.Write("<script>alert('" +comandoSQL+ "');</script>");
            MySqlCommand comando = new MySqlCommand(comandoSQL, conexao);
            comando.ExecuteNonQuery();
        }
        finally
        {
            conexao.Close();
        }
    }
}

And the form code . aspx:

<div class="col-xs-8 col-xs-offset-2 form-div">
    <form id="form1" runat="server">
        <div style="padding: 10px; padding-top: 50px; width: 400px; margin-left: auto; margin-right: auto; background-color: #f6f3f3;">


            <h3>Update your informations:</h3>

            <p>Name:</p>
            <asp:TextBox ID="txtNome" runat="server" CssClass="textobox" Width="382px"></asp:TextBox>
            <p>Facebook:</p>
            <asp:TextBox ID="txtFacebook" runat="server" CssClass="textobox" Width="182px"></asp:TextBox>
            <br />
            <p>Website:</p>
            <asp:TextBox ID="txtWebsite" runat="server" CssClass="textobox" Width="382px"></asp:TextBox>
            <p>Professional E-mail:</p>
            <asp:TextBox ID="txtEmail" runat="server" CssClass="textobox" Width="382px"></asp:TextBox>
            <p>City:</p>
            <asp:TextBox ID="txtLocal" runat="server" CssClass="textobox" Width="262px"></asp:TextBox>
            <p>State:</p>
            <asp:DropDownList ID="ddlEstado" runat="server"></asp:DropDownList>


            <br /><br /><br />
            <asp:Button ID="btnEnviar" runat="server" Text="Send" OnClick="btnEnviar_Click" />&nbsp;&nbsp;&nbsp;&nbsp;
            <br />
            <asp:Label ID="lblErros" runat="server"></asp:Label>
            <asp:TextBox ID="txtUsuario" runat="server" Visible="False"></asp:TextBox>
        </div>
    </form>
</div>
  • Where is the code???????

  • I put the code. Thank you.

  • Place the whole class (type where is for example the method of this button btnEnviar_Click) I need to check the complete cycle.

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.