How to retrieve Input data for CodeBehind ASP.net

0

My question is this: I have my HTML code and I'm doing field validation with JavaScript, but I would like to call the function and pass the value in CodeBehind. Example String name = uname (my input);

Is it 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>

    

    
asked by anonymous 09.01.2018 / 19:49

1 answer

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

Since validation is done with javascript you could do the following:

  • Run your validation javascript on a function that returns a bool
  • If you return true , your PostBack

In the following example, ValidarForm() would be its javascript function:

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

Note: Ideally, you should use the web controls of asp.net to be able to access data by code behind     

14.03.2018 / 22:11