How to Recover Data from Input to Codebehind ASP.net

Asked

Viewed 327 times

0

My question is the following: I have my HTML code and I am validating the fields with Javascript, but I would like to call the function and pass the value in Codebehind. Example String name = uname(my input);

It is possible ?

 <!--Form de Login -->
    <label><b>Usuario</b></label>
    <input type="text" runat="server" placeholder="Nome de Usuario" name="uname" id ="uname" onkeydown ="return soLetra();" onkeyup="return AutoTabular(40, uname, psw);" onkeypress ="return LimiteMaximoTextArea(uname, 15)" onclick ="return AlterarCampo(uname);"/>

    <label><b>Senha</b></label>
    <input type="password" runat="server" placeholder="Senha" name="psw" id ="psw" onkeypress="return LimiteMaximoTextArea(psw, 8);"/>

    <button type="submit" runat="server"  onclick ="teste2()">Login</button>
</div>

1 answer

0


If you are using Web Forms, it would be appropriate to use the controls of the asp.net (<asp:TextBox>).

whereas validation is being carried out with javascript you could do the following:

  • Perform your validation javascript in a function that will return a bool
  • If it is returned true, your will be made the PostBack

In the following example, ValidarForm() would be your job javascript:

<asp:Button ID="btnEntrar" Text="Entrar" OnClientClick="return ValidarForm();" OnClick="btnEntrar_Click" UseSubmitBehavior="false" runat="server" />

Note: The ideal is really that you use the web Controls of asp.net in order to be able to access the data by code Behind

Browser other questions tagged

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