Link to home
Start Free TrialLog in
Avatar of ITsolutionWizard
ITsolutionWizardFlag for United States of America

asked on

asp.net, auto populate

I have below html 5 control with auto complete (the auto complete basically read my database for all firstname in the person table)

<input type="text" name="firstname" id="lastname">

What I want to do is when the end user click one name in the list. then, it will read my database again, and capture all information from the name like

<input type="text" name="address" text="100 main streeet">
<input type="text name="city" text="los angeles">

How can I do that?
I use asp.net/c# web form
Avatar of Mlanda T
Mlanda T
Flag of South Africa image

The technique is basically to do the following:

1 -  Add a button on the client which the user will click to initiate the lookup or add a handler for the blur even in the textbox.

2 - One we know we need to make a call to the server, we read the value from the textbox and send it in an ajax request to the server. If course there had to be something in the server that can receive and prices this request (this will either be an aspx page method, a asmx Web service, a wcf service or an mvc controller)

3 -  rise server side service will receive the name, do a lookup and return an object with the relevant data

4 -  the ajax call will then come back to us with the data received from the server. And you then display the data.

You don't say anything about the asp.net development environment you're working with, but this might help..

http://codehandbook.org/javascript-json-encode-decode-with-asp-net-sample-code/


http://www.itorian.com/2013/02/jquery-ajax-get-and-post-calls-to.html?m=1
You could use the "close" or "select" event in your autocomplete plugin (assuming this is the JQuery Autocomplete plugin), and then make an AJAX call.

Here's an example:

HTML:
<input class="selector" placeholder="programming languages">

Open in new window


JQuery:

    var availableTags = [
      "ActionScript",
      "AppleScript",
      "Asp",
      "BASIC",
      "C",
      "C++",
      "Clojure",
      "COBOL",
      "ColdFusion",
      "Erlang",
      "Fortran",
      "Groovy",
      "Haskell",
      "Java",
      "JavaScript",
      "Lisp",
      "Perl",
      "PHP",
      "Python",
      "Ruby",
      "Scala",
      "Scheme"
    ];

$( ".selector" ).autocomplete({
	source: availableTags,
  select: function( event, ui ) {
        //ui.item.value is the selected item
       //make ajax call to get database data
  }
});

Open in new window


Here is a Fiddle Demo
Avatar of ITsolutionWizard

ASKER

i think you misunderstood me. I can do the auto complete one - just need to populate something on other textboxes
And that's why I suggested that you have a service on  the server side to which you send the name, it does the database lookup and returns the additional properties. It's really the same kind of setup you have on the autocomplete, just different information being passed along. You already know when a name has been clicked and so their you know when to initiate the autocomplete.
i just need to see sample codes....
ASKER CERTIFIED SOLUTION
Avatar of Mlanda T
Mlanda T
Flag of South Africa image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial