0

i have problems here. i have two textbox: textbox1 and textbox2 : Order and Buyer. i want to make if user type order in textbox1 and they click enter or using mouse click, the buyer based on order will appear in textbox2. how to achieve this in asp.net webpage using c# ? because it does not have keypress or something that i want to write code. i dont want to use any button because i have any other requirements must enter before click button submit. just those two textbox ? someone help ?

protected void TextBoxJO_TextChanged(object sender, EventArgs e)
{
DataTable dt=new DataTable();

query = "select cusfname from mescomm..CustomerLib a, mestrans..JobOrder_HD b where a.cuscode = b.customer_cd and po_no ='" + TextBoxJO.Text + "'";
cmd = new SqlCommand(query);
SqlDataReader reader = cmd.ExecuteReader();
if (reader.Read())
{
    TextBoxBuyer.Text = reader["cusfname"].ToString();

    reader.Close();
    con.Close();
}

}
alessandrio
  • 4,282
  • 2
  • 29
  • 40
NFH
  • 17
  • 8
  • You could use javascript to bind an event to `textbox1`, then modify content of `textbox2`, If you really don't know how to do this, I'd suggest studying a bit more about javascript, maybe applying to a course, and doing some more research before asking here, then you could share what you had tried and what went wrong. – Alisson Reinaldo Silva Jun 01 '17 at 01:42

2 Answers2

0

You can change text of Text box using Java script . Just use your Asp:TextBox instead of

function change()
{
var t1=document.getElementById('txt1');
var t2=document.getElementById('txt2');
t2.value=t1.value;
}
Enter in this Text box..
<br/>
<input id='txt1' oninput="change()" />
Second Text Box...
<br/>
<input id='txt2' />
rtraees
  • 312
  • 2
  • 15
  • how about using textchanged event in textbox ? did it work ? other than javascript ? – NFH Jun 01 '17 at 03:14
  • @NFH You can implement it using TextChangedEvent too. But, Problem in that is you can't handle it asynchronously without using update panel. In that case it would be long way to do. I'll suggest you to use Jquery to handle such functionality. – Chirag Jun 01 '17 at 03:39
  • i want to retrieve data in textbox2 from database. after textbox1 value match with value in database. it is possible to create in javascript ? – NFH Jun 01 '17 at 04:39
  • it is possible with ajax. you May try https://stackoverflow.com/questions/28943640/get-information-from-database-with-ajax-asp-net or you just go through 3 or 4 tutorial on AJAX https://www.w3schools.com/xml/ajax_intro.asp its quite simple. – rtraees Jun 02 '17 at 05:53
0

i used above code textchanged event for textbox and add autopostback=true. it works ! thankyou :)

NFH
  • 17
  • 8