Jump to content

Problems with textbox.


aic007

Recommended Posts

Hi.I'm very new with ASP (and C# also), so I thought I could ask some experts here for help :) I was wondering if sombody here could tell me what to do in order to get one or more textboxes to retrieve information automaticly ?For instance, if I type in the employee nr, I want the name and adress textboxes to be filled in automaticly.I really don't know how to do it. Can somebody plzz help me or show me some examples ?

Link to comment
Share on other sites

In order to populate those fields with data from some data source (e.g. a database), you'll have to make a call to the server. The easy way would be for the user to type in a value into the employee ID box and hit submit to post the request back to the server. Then, on the server, check that value against the data source and populate the other two text boxes with that data and send the response back to the user.A more challenging way is to use AJAX to send that request to the server so the user doesn't have to submit the entire page.This article (http://www.codeproject.com/aspnet/GoogleSuggestDictionary.asp) may help get you started.

Link to comment
Share on other sites

It's not too bad if you take it one step at a time. First, you might figure out where that data is going to be coming from. If it's going to be coming from an XML file, then you'll want to look around for some tutorials about how to load XML files and read their data.If it's going to be coming from a database, check out how to set up databases. Once the database is set up, look for tutorials about making a connection to the database and retrieving data.Projects are definitely difficult and confusing when you first approach them, especially when you are learning a new technology. Just take it one step at a time and you'll get there.

Link to comment
Share on other sites

Well, if you want to go the easy route:.ASPX

<form runat="server" id="UserForm"><asp:TextBox id="EmployeeID" runat="server" /><asp:Button id="SubmitButton" runat="server" OnClick="SubmitButton_Click" Text="Submit" /><asp:TextBox id="EmployeeName" runat="server" Visible="false" /></form>

.ASPX.CS

protected void Page_Load(object sender, EventArgs e){}protected void SubmitButton_Click(object sender, EventArgs e){	int _employeeID;	int.TryParse(EmployeeID.Text, out _employeeID);	// _employeeID now has the integer value of the employee id 	// entered by the user.  Use that integer to get the data from the database	// once you have the data you can set the value to your EmployeeName text box:		EmployeeName.Text = _employeeName;	EmployeeName.Visible = true;}

If you want to go the AJAX route, head over to the AJAX tutorial here: http://www.w3schools.com/ajax/default.asp

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...