How do I get the User Entered Value in AjaxControlToolkit ComboBox when the enter key is pressed?

Posted by Jason on Stack Overflow See other posts from Stack Overflow or by Jason
Published on 2010-06-10T20:30:15Z Indexed on 2010/06/10 20:32 UTC
Read the original article Hit count: 481

Filed under:
|
|

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();
}

© Stack Overflow or respective owner

Related posts about c#

Related posts about ASP.NET