0

i want to create a web page with a textbox and a gridview. as you type in the textbox i want the content of grid view to be retrieved from database according to the text of textbox. i am also using ajax. is there any way to get the text from textbox as user types in and pass it to the server side code? i searched on google but the only thing i got was keypress event using jquery or java and display it using java again. but there was nothing about passing it to the code behind.

Thanks and pardon my poor English :(

Ali.Rashidi
  • 1,284
  • 4
  • 22
  • 51

2 Answers2

1

In asp.net you can specify the AutoPostBack="true" on a textbox this will fire an postback after you lose focus of that TextBox, so not on every keystrike if you desire to have a postback on every keystrike you will have to implement some javascript knowledge.

Here you can find an example: How do I make a Textbox Postback on KeyUp?

But I believe you are more interessted in a AutoCompleteBox maybe give this link a try: http://www.asp.net/ajaxLibrary/AjaxControlToolkitSampleSite/AutoComplete/AutoComplete.aspx

Community
  • 1
  • 1
Rand Random
  • 7,300
  • 10
  • 40
  • 88
  • actually auto complete is not what i want. Its sort of auto complete but suggestion are displayed on a grid view. – Ali.Rashidi Aug 02 '13 at 09:12
  • Than the first link, I have provided is perfect for you. – Rand Random Aug 02 '13 at 09:13
  • would you please tell me what are the parameters that __doPostBack takes? – Ali.Rashidi Aug 02 '13 at 09:32
  • The first one is the __EVENTTARGET and the second the __EVENTARGUMENT. So the first is the control that fires the postback, so the clientID of your button and the second one is a addiontal argument that you can give. Which isnt necessary in your case since the ViewState is holding the text of your textbox, but if you would have disabled viewstate you could use the argument to pass the text of the textbox or anything you like to share. It just takes any string, so you could fill it with all day long JSON stuff and parse it on server side. – Rand Random Aug 02 '13 at 09:47
0

As you said, you can use the java key press event. Then you can create an ajax request and ask the server for data.

You should make sure that the data you are requesting can be retrieved very fast, otherwise you would have a delay when typing. Maybe it's a better approach to fetch the whole result and filter it while typing.

A small example can be found here: Making a Simple Ajax call to controller in asp.net mvc

Other examples can be found with your friend google.com :-)

Community
  • 1
  • 1
DerApe
  • 3,097
  • 2
  • 35
  • 55