I'm trying to implement a cascading type behvaior between RadComboBoxes so that a second ComboBox gets populated when a user checks items in the first ComboBox. I've wired up a handler on the OnTextChanged event because I wanted my logic to execute after a users has finished checking the desired items not after each item is checked. I'm setting the initial checked items in the first ComboBox during Page Load based on an existing record in the Database. What I'm noticing is that the OnTextChanged event is firing during the first Post Back to the page regardless of which control initiated the Post Back. I've mocked up a sample page to recreate the behavior.
aspx:
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Test2.aspx.cs" Inherits="Test2" %>
<!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
style
=
"background-color: #c3cce5"
>
<
form
id
=
"form1"
runat
=
"server"
>
<
telerik:RadScriptManager
ID
=
"RadScriptManager1"
runat
=
"server"
>
</
telerik:RadScriptManager
>
<
telerik:RadComboBox
ID
=
"RadDropDownList"
runat
=
"server"
MaxHeight
=
"300px"
Width
=
"200px"
DropDownAutoWidth
=
"Enabled"
OnTextChanged
=
"RadDropDownList_TextChanged"
EmptyMessage
=
"--Choose--"
CheckBoxes
=
"true"
AutoPostBack
=
"true"
>
<
Items
>
<
telerik:RadComboBoxItem
Value
=
"test1"
Text
=
"Test1"
/>
<
telerik:RadComboBoxItem
Value
=
"test2"
Text
=
"Test2"
/>
<
telerik:RadComboBoxItem
Value
=
"test3"
Text
=
"Test3"
/>
<
telerik:RadComboBoxItem
Value
=
"test4"
Text
=
"Test4"
/>
<
telerik:RadComboBoxItem
Value
=
"test5"
Text
=
"Test5"
/>
</
Items
>
</
telerik:RadComboBox
>
<
asp:Button
ID
=
"UpdateButton"
runat
=
"server"
Text
=
"Update"
OnClick
=
"UpdateButton_Click"
/>
</
form
>
</
body
>
</
html
>
aspc.cs:
using
System;
using
System.Collections.Generic;
using
System.Linq;
using
System.Web;
using
System.Web.UI;
using
System.Web.UI.WebControls;
using
Telerik.Web.UI;
public
partial
class
Test2 : System.Web.UI.Page
{
protected
void
Page_Load(
object
sender, EventArgs e)
{
if
(Page.IsPostBack)
{
System.Diagnostics.Debug.WriteLine(
"Page Load PostBack"
);
}
else
{
System.Diagnostics.Debug.WriteLine(
"Page Load No PostBack"
);
//Select a value
if
(RadDropDownList.FindItemByText(
"Test3"
) !=
null
)
{
RadDropDownList.FindItemByText(
"Test3"
).Checked =
true
;
}
}
}
protected
void
RadDropDownList_TextChanged(
object
sender, EventArgs e)
{
System.Diagnostics.Debug.WriteLine(
"RadDropDownList_TextChanged"
);
}
protected
void
UpdateButton_Click(
object
sender, EventArgs e)
{
System.Diagnostics.Debug.WriteLine(
"UpdateRuleButton_Click"
);
}
}
When I run the page, I see the following output:
Page Load No PostBack
When I click on the Update Button (i.e. I haven't changed anything in the ComboBox), I see the following output:
Page Load PostBack
RadDropDownList_TextChanged
UpdateRuleButton_Click
Notice that the RadDropDownList_TextChanged method is getting called even though the postback was initated from the Update Button. Why/how is the RadDropDownList_TextChanged getting executed? Is it due to the fact of me setting the value during Initial Page Load?
If I click the Button again, I get the expected behavior:
Page Load PostBack
UpdateRuleButton_Click
If I comment out the checking of the Item during Page Load of the ComboBox, then I don't experience the weird Behavior. Wondering if this is a bug or working as designed.