How do I get the User Entered Value in AjaxControlToolkit ComboBox when the enter key is pressed?
- by Jason
The Problem:
The user entered value is missing in the .Text attribute of the AjaxControlToolkit ComboBox when the enter key pressed. Also the “on change” events events are not called but I am not using postbacks anyway so I do not care.
Example:
private void BuildFileListDetails(NHibernateDataProvider _providerM)
{
int resultsPage = Convert.ToInt32(ddlNavPageNumber.Text);
const int RESULTS_PAGE_SIZE = 100;
// The cbFileName.Text equals "" Not what user entered
string searchFileName= cbFileName.Text;
var xrfFiles = _providerM.GetXrfFiles(searchFileName, resultsPage, RESULTS_PAGE_SIZE);
gvXrfFileList.DataSource = xrfFiles;
gvXrfFileList.DataBind();
}
My Solution:
I needed to access the AjaxToolkit "ComboBox" imbedded TextBox control's .Text to access the value entered by user.
private void BuildFileListDetails(NHibernateDataProvider _providerM)
{
int resultsPage = Convert.ToInt32(ddlNavPageNumber.Text);
const int RESULTS_PAGE_SIZE = 100;
string searchFileName;
//The Solution: Access the AjaxToolkit "ComboBox" imbedded TextBox control's .Text to access the value entered by user.
TextBox textBox = cbFileName.FindControl("TextBox") as TextBox;
if (textBox != null)
{
searchFileName = textBox.Text; //textBox.Text = "User Entered Value"
}
else
{
searchFileName = cbFileName.Text;
}
var xrfFiles = _providerM.GetXrfFiles(searchFileName, resultsPage, RESULTS_PAGE_SIZE);
gvXrfFileList.DataSource = xrfFiles;
gvXrfFileList.DataBind();
}