calling function inside the javascript tag in the code behind file

Posted on 2005-05-09
Last Modified: 2012-08-13
I have a textbox in which the user can scan the item no. All the items which are scanned/entered are being added in the grid below the text box.

I want that if the length of the item number is 7 ,page should be refreshed automatically and the item should be added in the grid.

txtItem.Attributes.Add("onKeyUp", "Javascript:if(document.forms[0].txtItem.value.length==7) { document.forms[0].txtSaleQty.focus();}")

the above code taked the focus to the txtSaleQty textbox when the length is 7. Is possible to do the following:

txtItem.Attributes.Add("onKeyUp", "Javascript:if(document.forms[0].txtItem.value.length==7) { CALL THE VB.NET FUNCTION BINDDATA}")

BINDDATA inserts the record in the database and refreshes the grid.

I tried adding the binddata in the TEXT CHANGED event of the txtItem textbox but the ENTER key has to be pressed to fire that event so that doesn't work for me.

Question by:wilkersons
    LVL 13

    Accepted Solution

    You need to set up a form for data entry, process the form on submit on the server side. You can't call a server-side function directly on the client side. Once you have the form, you can have it do " document.myform.submit(); " (assuming your form is named "myform") when you reach 7 characters.

    e.g. (using your forms[0] to access the form)
    txtItem.Attributes.Add("onKeyUp", "Javascript:if(document.forms[0].txtItem.value.length==7) { document.forms[0].submit();}")

    Does that make sense? :)

    Author Comment


    So adding  this
    txtItem.Attributes.Add("onKeyUp", "Javascript:if(document.forms[0].txtItem.value.length==7) { document.forms[0].submit();}")

    Should I add the BINDDATA procedure in the text changed event of the txtItem and set autopostback to true??
    LVL 13

    Expert Comment

    Almost :) - Don't autopostback, you're submitting the form so there is no need for that. and yes, put your binddata procedure into the text changed event.

    Author Comment

    That works...thanks!!

    Featured Post

    How your wiki can always stay up-to-date

    Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
    - Increase transparency
    - Onboard new hires faster
    - Access from mobile/offline

    Join & Write a Comment

    In an ASP.NET application, I faced some technical problems. In this article, I list them out and show the solutions that I found.  I hope it will be useful. Problem: After closing a pop-up window, the parent page should be refreshed automaticall…
    IntroductionWhile developing web applications, a single page might contain many regions and each region might contain many number of controls with the capability to perform  postback. Many times you might need to perform some action on an ASP.NET po…
    Sending a Secure fax is easy with eFax Corporate ( First, Just open a new email message.  In the To field, type your recipient's fax number You can even send a secure international fax — just include t…
    This video discusses moving either the default database or any database to a new volume.

    734 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    20 Experts available now in Live!

    Get 1:1 Help Now