Skip Navigation LinksHome / Community & Support / Developer Productivity Tools Forums / ASP.NET > Combobox > Stop Postback When Combobox Loses Focus
RadControls for ASP.NET are no longer supported (see this page for reference). In case you have inquiries about the Telerik ASP.NET AJAX controls, post them in the pertinent ASP.NET AJAX forums.

Answered Stop Postback When Combobox Loses Focus

Feed from this thread
  • Mark Wells avatar

    Posted on Mar 26, 2010 (permalink)

    Hi,

    I need to be able to stop the combobox from posting back when it loses focus. I am using it as a load on demand box that returns search results. When the user chooses a selection, I handle the SelectedIndexChanged event and this is fine. The problem happens when they do not choose a result and decide to click on a button to do something. What happens is that the combobox loses focus and does a postback which negates the button click event. Consequently, the user must click on the button again to re-instate
    the button click event.

    I tried to handle the OnClientBlur event and return false but that doesn't stop the postback.

    Is there anyway I can do this?

    Thanks,

    Mark

  • Simon Simon admin's avatar

    Posted on Mar 29, 2010 (permalink)

    Hi Mark Wells,

    Before providing you with the workaround I tried recreating the issue without success.

    Can you please see the attached page and let me know if I am missing something?

    All the best,
    Simon
    the Telerik team

    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.

  • Mark Wells avatar

    Posted on Mar 29, 2010 (permalink)

    Hi Simon,

    I was able to re-create the problem with the code that you supplied. The postback happens if the user typed into the combobox but did not choose one of the supplied options. The user then clicks outside the box so that it loses focus and it does the postback.

    I am using a different version than you so I am providing you code with the changes that I made.

    <%@ Page Language="C#" AutoEventWireup="true" CodeFile="StopPostbackOnBlurIfNoSelectedItem.aspx.cs" Inherits="_Default" %> 
     
    <%@ Register TagPrefix="telerik" Namespace="Telerik.WebControls" Assembly="RadComboBox.Net2" %> 
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> 
    <html xmlns="http://www.w3.org/1999/xhtml">  
    <head runat="server">  
        <title></title>  
    </head> 
    <body> 
        <form id="form1" runat="server">  
        <asp:ScriptManager ID="ScriptManager1" runat="server" /> 
        <div> 
            <telerik:RadComboBox ID="RadComboBox1" runat="server" AutoPostBack="true" EnableLoadOnDemand="true">  
            </telerik:RadComboBox> 
        </div> 
        </form> 
    </body> 
    </html> 
     
    using System;  
    using System.Collections.Generic;  
    using System.Web;  
    using System.Web.UI;  
    using System.Web.UI.WebControls;  
     
    public partial class _Default : System.Web.UI.Page  
    {  
        protected void Page_Load(object sender, EventArgs e)  
        {  
            RadComboBox1.ItemsRequested += new Telerik.WebControls.RadComboBoxItemsRequestedEventHandler(RadComboBox1_ItemsRequested);  
        }  
     
        void RadComboBox1_ItemsRequested(object o, Telerik.WebControls.RadComboBoxItemsRequestedEventArgs e)  
        {  
            for (int i = 0; i < 3; i++)  
            {  
                RadComboBox1.Items.Add(new Telerik.WebControls.RadComboBoxItem("item" + i));  
            }  
        }  
    }  
     

  • Answer Simon Simon admin's avatar

    Posted on Mar 30, 2010 (permalink)

    Hi Mark Wells,

    Thank you for the clarification.

    This happens because the classic RadComboBox postbacks if its Text is changed as well.

    You can avoid this by handling the client-side Blur event in this way:
    function onBlur(comboBox) {
        comboBox.OriginalText = comboBox.GetText();
    }

    Regards,
    Simon
    the Telerik team

    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.

  • Mark Wells avatar

    Posted on Mar 30, 2010 (permalink)

    Thank you Simon. The onBlur function that you provided solves my problem.

  • Sid avatar

    Posted on Apr 1, 2011 (permalink)

    Hi,
    I tried suggested code, but I got following error, Object doesn't support this property or method.

    Regards Sid

  • Simon Simon admin's avatar

    Posted on Apr 6, 2011 (permalink)

    Hi Sid,

    You are most probably using the ASP.NET AJAX version of RadComboBox, which has a different API. You can use the following code instead:
    function onBlur(comboBox) {
        comboBox._originalText = comboBox.get_text();
    }

    I hope this helps.

    Kind regards,
    Simon
    the Telerik team
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items

Back to Top

Skip Navigation LinksHome / Community & Support / Developer Productivity Tools Forums / ASP.NET > Combobox > Stop Postback When Combobox Loses Focus