ASP.net VB.net Call procedure when a user hits Enter in a TextBox

Hi

I have an ASP.net TextBox. After the user has typed something and presses enter I want to call a VB.net
procedure called oInsertValues. How do I do this?

Thanks
Murray BrownMicrosoft Cloud Azure/Excel Solution DeveloperAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Chinmay PatelChief Technical NinjaCommented:
Hi Murray,

Ideally, you would do this
1. Bind an onchange(JavaScript) event with your textbox

The Textbox
<asp:TextBox ID="YOURTEXTBOX" runat="server" onchange="oInsertValues(this)"></asp:TextBox>

Open in new window


JavaScript - Please put it at the end of your page HTML
// Assuming your ASP.Net page has included JQuery
<script type = "text/javascript">
function oInsertValues() {
// Write a code here to check how many keypresses, since we sent the request
    $.ajax({
        type: "POST",
        url: "YOURASPXFILE.aspx/oInsertValues",
        data: '{values: "' + this.value + '" }',
        contentType: "application/json; charset=utf-8",
        dataType: "json",
        success: OnSuccess,
        failure: function(response) {
            alert("Error : " + response.d);
        }
    });
}
function OnSuccess(response) {
    // Handle your success Scenario
}
</script>

Open in new window


CodeBehind Web Method
<System.Web.Services.WebMethod()> _
Public Shared Function oInsertValues(ByVal values As String) As Bool
' Insert your code here
   Return True
End Function

Open in new window


It is generally set up so that after a particular number of key presses (you really do not want to send a request on every keystroke - it generally degrades the end user experience) - you will call the server side method

Let me know if you need further help.

Regards,
Chinmay.
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Murray BrownMicrosoft Cloud Azure/Excel Solution DeveloperAuthor Commented:
Thanks very much
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
ASP.NET

From novice to tech pro — start learning today.