This is a migrated thread and some comments may be shown as answers.

button click event not firing when combobox text changed

1 Answer 149 Views
Ajax
This is a migrated thread and some comments may be shown as answers.
Igor
Top achievements
Rank 1
Igor asked on 06 Nov 2008, 11:43 PM
I have a pageview in multipage. In pageview RadComboBox is defined and button is defined.
Combobox asllows custom text and selectedindexchanged event is impelemtned on server.
button click event is implemented on server.

when text changed in combobox and button clicked, only selectedindexchanged is fired, button click event is not fired.

I wonder how can I get both events fired.

I have a small project included:

<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Default.aspx.cs" Inherits="testproj._Default" %> 
 
<%@ Register Assembly="Telerik.Web.UI" Namespace="Telerik.Web.UI" TagPrefix="telerik" %> 
 
<!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>Untitled Page</title> 
</head> 
<body> 
    <form id="form1" runat="server">  
    <div> 
        <telerik:RadScriptManager ID="RadScriptManager1" runat="server">  
        </telerik:RadScriptManager> 
        <telerik:RadAjaxManager ID="RadAjaxManager1" runat="server">  
            <AjaxSettings> 
                <telerik:AjaxSetting AjaxControlID="RadMultiPage1">  
                    <UpdatedControls> 
                        <telerik:AjaxUpdatedControl ControlID="RadMultiPage1" /> 
                    </UpdatedControls> 
                </telerik:AjaxSetting> 
            </AjaxSettings> 
        </telerik:RadAjaxManager> 
        <telerik:RadMultiPage ID="RadMultiPage1" runat="server" SelectedIndex="0">  
            <telerik:RadPageView ID="RadPageView1" runat="server">  
                <telerik:RadComboBox ID="RadComboBox1" Runat="server" AllowCustomText="True"   
                    AutoPostBack="True" ChangeTextOnKeyBoardNavigation="False"   
                    onselectedindexchanged="RadComboBox1_SelectedIndexChanged"   
                    ShowDropDownOnTextboxClick="False">  
                    <Items> 
                        <telerik:RadComboBoxItem runat="server" Text="RadComboBoxItem1"   
                            Value="RadComboBoxItem1" /> 
                        <telerik:RadComboBoxItem runat="server" Text="RadComboBoxItem2"   
                            Value="RadComboBoxItem2" /> 
                    </Items> 
                    <CollapseAnimation Duration="200" Type="OutQuint" /> 
                </telerik:RadComboBox><br /> 
                <asp:Button ID="Button1" runat="server" Text="Button" onclick="Button1_Click" /> 
                <br /> 
                <asp:Label ID="Label1" runat="server" Text="Label"></asp:Label> 
                <asp:Label ID="Label2" runat="server" Text="Label"></asp:Label> 
            </telerik:RadPageView> 
            <telerik:RadPageView ID="RadPageView2" runat="server">  
                pageview2  
            </telerik:RadPageView> 
            <telerik:RadPageView ID="RadPageView3" runat="server">  
                pageview3  
            </telerik:RadPageView> 
        </telerik:RadMultiPage> 
    </div> 
    </form> 
</body> 
</html> 
 
using System;  
using System.Collections;  
using System.Configuration;  
using System.Data;  
using System.Linq;  
using System.Web;  
using System.Web.Security;  
using System.Web.UI;  
using System.Web.UI.HtmlControls;  
using System.Web.UI.WebControls;  
using System.Web.UI.WebControls.WebParts;  
using System.Xml.Linq;  
 
namespace testproj  
{  
    public partial class _Default : System.Web.UI.Page  
    {  
        protected void Page_Load(object sender, EventArgs e)  
        {  
 
        }  
 
        protected void RadComboBox1_SelectedIndexChanged(object o, Telerik.Web.UI.RadComboBoxSelectedIndexChangedEventArgs e)  
        {  
            Label1.Text = "selected index changed";  
        }  
 
        protected void Button1_Click(object sender, EventArgs e)  
        {  
            Label2.Text = "button clicked";  
        }  
    }  
}  
 

1 Answer, 1 is accepted

Sort by
0
Kevin Babcock
Top achievements
Rank 1
answered on 08 Nov 2008, 03:16 AM
Hello Igor,

I suspect your Button's OnClick event is not getting fired because you have set the RadComboBox's AutoPostBack property to true. What happens is when you change the RadComboBox selection, it send a post back to the server, which only fires the RadComboBox's SelectedIndexChanged event. When you click the Button, it sends a separate postback to the server, which fires the Buttons OnClick event. You won't see both events fired during the same post back because each control causes a post back separately. If you want to require the Button control be clicked to post the RadComboBox change back to the server, set the AutoPostBack property to false. Then when you click the Button, both the OnSelectedIndexChanged and the OnClick events will fire during the same post back.

I hope that helps. If you have any additional questions, please let me know.

Regards,
Kevin Babcock
Tags
Ajax
Asked by
Igor
Top achievements
Rank 1
Answers by
Kevin Babcock
Top achievements
Rank 1
Share this question
or