1

I have an old VB.Net application that I need to modify some functionalities, I added:

<input type="text" id="hiddenAccountNumber" class="js-card" placeholder="Test" onkeypress="readKeyPress()"/>

The function readKeyPress has some logic to read the data in the input once you do Enter with the keyboard... My problem is that everytime a hit Enter on the keyboard the whole page do a PostBack and my javascript code is never executed... I need my javascript code execute only. Any idea please?

I don't see any Form tag actually this is a piece of the code:

<asp:Content ID="Content2" ContentPlaceHolderID="body" runat="server">

    <asp:ScriptManager ID="ScriptManager1" runat="server">
    </asp:ScriptManager>

    <div class="AccountSummary" style="float:right;">
         <uc:AccountSummary id="ucAccountSummary" runat="server" />
    </div>

    <asp:UpdatePanel ID="updateTransactionControls" runat="server" >
        <ContentTemplate>

But it has a few UC and has this triggers:

<Triggers>
            <asp:AsyncPostBackTrigger ControlID="ucGeneralPaymentPosting" 
                EventName="SetupPaymentForm" />
            <asp:AsyncPostBackTrigger ControlID="ucGeneralPaymentPosting" 
                EventName="ClearPaymentForm" />
            <asp:AsyncPostBackTrigger ControlID="ucDentalFirstFinancing" 
                EventName="InvalidDentalFirstSSN" />
            <asp:AsyncPostBackTrigger ControlID="btnReviewPayment" EventName="Click" />
            <asp:AsyncPostBackTrigger ControlID="btnBackToCollectData" EventName="Click" />
            <asp:AsyncPostBackTrigger ControlID="ucCareCredit" 
                EventName="ShowAuthorizationForm" />
            <asp:AsyncPostBackTrigger ControlID="btnSubmitPayment" EventName="Click" />
            <asp:AsyncPostBackTrigger ControlID="btnDelete" EventName="Click" />
            <asp:AsyncPostBackTrigger ControlID="btnDelete" EventName="Click" />
            <%--<asp:AsyncPostBackTrigger ControlID="ucThirdPartyLenderAccountInformation" EventName="CheckEmailSelection" />--%>
        </Triggers>
Jose Raul Perera
  • 778
  • 1
  • 7
  • 35

1 Answers1

0

You'll have to return false to prevent Postback:

onkeypress="readKeyPress(); return false;"

Or at the end of your readKeyPress() function.

Using an UpdatePanel and ScriptManager from Ajax Control Toolkit would be another option.

EDIT:

Then you'll have to call the preventDefault() method:

https://www.w3schools.com/jsref/event_preventdefault.asp

Here's an example:

https://stackoverflow.com/a/19379604/1821637

Máster
  • 981
  • 11
  • 23