views:

28

answers:

1

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"
    }

    var xrfFiles = _providerM.GetXrfFiles(searchFileName, resultsPage, RESULTS_PAGE_SIZE);
    gvXrfFileList.DataSource = xrfFiles;
    gvXrfFileList.DataBind();
}
A: 

I ended up creating Utility Method to fix this issue, to be executed before first use of the ComboBox.Text property. Since the AjaxToolKit ComboBox has a drop down sub component, I needed to check the drop down list to see if the new value already exists in the list and add it if it is missing before assigning the new text value.

//*****************************************************************
// Fix AjaxToolKit ComboBox Text when Enter Key is pressed bug.
//*****************************************************************
public void FixAjaxToolKitComboBoxTextWhenEnterKeyIsPressedIssue(AjaxControlToolkit.ComboBox _combobox)
{
    TextBox textBox = _combobox.FindControl("TextBox") as TextBox;
    if (textBox != null)
    {
        if (_combobox.Items.FindByText(textBox.Text) == null)
        {
            _combobox.Items.Add(textBox.Text);
        }
            _combobox.Text = textBox.Text;
        }
    }
}
Jason