ASP.NETX conditional onkeydown event

Asked

Viewed 59 times

3

I have an ASP form with 2 Divs with some fields to fill in, but there is a flag in the user’s profile that can or cannot hide one of them

protected void Page_Load(object sender, EventArgs e)
    {
                dvValidade.Visible = (bool)Session["confVal"]; //valido o perfil
    }  

Div:

<div class="ConfProdText" id="dvValidade" runat="server" visible="true">
    --Codigo aqui
</div>

So far this works, the problem is that in div previous, there is a <asp:TextBox> with a function to click the send button:

<div>
<asp:TextBox ID="txtQntdeConfe" class="textbox" Width="89px" MaxLength="11" Rows="1" AutoComplete="off" runat="server" onFocus="this.select();" type="number" step="0.001" onkeydown="if(event.keyCode == 9) document.getElementById('ContentPlaceHolder1_btnEnviar').click()"/>

<div>

What I need is that when I go dvValidade.Visible = true, that the condition within the onkeydown of the textbox do not execute

WHAT I HAVE DONE:

I tried to change the condition to:

onkeydown="if(event.keyCode == 9 && $('#ContentPlaceHolder1_dvValidade').is(':hidden')) document.getElementById('ContentPlaceHolder1_btnEnviar').click()"

and put the dvValidade with display="none":

<div style="margin-left: 1px; text-align: left;" class="ConfProdText" id="dvValidade" runat="server" visible="true" display="none">
.
.
.
</div>

but I couldn’t change the property value display, and even though none he tries to find the textbox

  • When it gives tab and the expiration date is hidden calls the send click is this ? And it didn’t work ? If it didn’t work what happened ? Error on console ? Can you see the None display on <div> ? console.log($('#ContentPlaceHolder1_dvValidade').is(':hidden'))) show him what ?

  • @Isac When it is hidden, it works, it calls the click of the button and ta ok. the problem is when it is not, because when it goes to the field txtQntdeConfe he calls the field, but there are still 2 new fields to be filled. what I need, is a way of, inside the onkeydown, it identify whether ta visible or not, so then yes decide whether to execute the click or follow the normal behavior of TAB

  • I know it’s a little weird, but this page is being made to run on a barcode collector, and the easiest button to access is the TAB

  • 1

    But you still haven’t answered some of the questions I asked in my first comment, and in particular regarding console.log. Anyway this seems clearly problem of html and javascript, and not related to Asp.net, but by your question it is not clear what is not working and what problem you have. My suggestion is that you create one Minimum, Complete and Verifiable Example problem, through the question snippet so that it is easy for us to see and reproduce the problem.

No answers

Browser other questions tagged

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