I have a Master Page which has the RadAjaxManager , RadLoadingPanel, RadScriptManager
I have a Parent Page A which uses the Master Page. The Parent Page has a Combo box control with 7 provinces; Each Province has a User Control ( View ). By default , the selected index is province "SK" which loads in the same page a user control View dynamically.
Below is my HTML and Code behind for the Parent Page
<
telerik:RadAjaxManagerProxy
ID
=
"RadAjaxManagerProxy1"
runat
=
"server"
>
<
AjaxSettings
>
<
telerik:AjaxSetting
AjaxControlID
=
"cmbProvince"
>
<
UpdatedControls
>
<
telerik:AjaxUpdatedControl
ControlID
=
"phPPSAControl"
UpdatePanelHeight
=
"100%"
/>
</
UpdatedControls
>
</
telerik:AjaxSetting
>
</
AjaxSettings
>
</
telerik:RadAjaxManagerProxy
>
<
telerik:RadComboBox
ID
=
"cmbProvince"
runat
=
"server"
OnSelectedIndexChanged
=
"cmbProvince_SelectedIndexChanged"
AutoPostBack
=
"true"
>
<
Items
>
<
telerik:RadComboBoxItem
runat
=
"server"
Text
=
"Quebec"
Value
=
"QC"
/>
<
telerik:RadComboBoxItem
runat
=
"server"
Text
=
"Ontario"
Value
=
"ON"
/>
<
telerik:RadComboBoxItem
runat
=
"server"
Text
=
"Saskatchewan"
Value
=
"SK"
/>
<
telerik:RadComboBoxItem
runat
=
"server"
Text
=
"Manitoba"
Value
=
"MB"
/>
<
telerik:RadComboBoxItem
runat
=
"server"
Text
=
"Yukon"
Value
=
"YT"
/>
<
telerik:RadComboBoxItem
runat
=
"server"
Text
=
"Nuvanut"
Value
=
"NU"
/>
</
Items
>
</
telerik:RadComboBox
>
<
asp:PlaceHolder
ID
=
"phPPSAControl"
runat
=
"server"
></
asp:PlaceHolder
>
private string _currentProvince = "";
protected void Page_PreInit(object sender, EventArgs e)
{
MasterPage master = this.Master;
_currentProvince = GetCurrentOperatingProvince(IsPostBack);
cmbProvince.SelectedValue = _currentProvince;
txtReferenceNo.Text = "TECHLOS" + DateTime.Now.ToString("MMddyyyy-HHMMss");
//Reload Dynamic Control on Every Page Creation
LoadDetailControl();
}
/// <
summary
>
/// Handles the SelectedIndexChanged event of the cmbProvince control.
/// </
summary
>
/// <
param
name
=
"sender"
>The source of the event.</
param
>
/// <
param
name
=
"e"
>The <
see
cref
=
"Telerik.Web.UI.RadComboBoxSelectedIndexChangedEventArgs"
/> instance containing the event data.</
param
>
protected void cmbProvince_SelectedIndexChanged(object sender, RadComboBoxSelectedIndexChangedEventArgs e)
{
phPPSAControl.Controls.Clear();
_currentProvince = e.Value;
LoadDetailControl();
}
/// <
summary
>
/// Loads the detail control based on _currentProvince
/// </
summary
>
private void LoadDetailControl()
{
UserControl ucPPSAControl = (UserControl)LoadControl(GetUserControlPath(_currentProvince));
IPPSAView provView = ucPPSAControl as IPPSAView;
ApplicationContext.TargetProvince = _currentProvince;
PPSAPresenter presenter = new PPSAPresenter(provView, ApplicationContext);
provView.AttachPresenter(presenter, cmbProvince.SelectedValue, txtReferenceNo.Text);
phPPSAControl.Controls.Add(ucPPSAControl);
}
<
telerik:RadAjaxManagerProxy
ID
=
"RadAjaxManagerProxy1"
runat
=
"server"
>
<
AjaxSettings
>
<
telerik:AjaxSetting
AjaxControlID
=
"cmbProvince"
>
<
UpdatedControls
>
<
telerik:AjaxUpdatedControl
ControlID
=
"phPPSAControl"
UpdatePanelHeight
=
"100%"
/>
</
UpdatedControls
>
</
telerik:AjaxSetting
>
</
AjaxSettings
>
</
telerik:RadAjaxManagerProxy
>
<
telerik:RadComboBox
ID
=
"cmbProvince"
runat
=
"server"
OnSelectedIndexChanged
=
"cmbProvince_SelectedIndexChanged"
AutoPostBack
=
"true"
>
<
Items
>
<
telerik:RadComboBoxItem
runat
=
"server"
Text
=
"Quebec"
Value
=
"QC"
/>
<
telerik:RadComboBoxItem
runat
=
"server"
Text
=
"Ontario"
Value
=
"ON"
/>
<
telerik:RadComboBoxItem
runat
=
"server"
Text
=
"Saskatchewan"
Value
=
"SK"
/>
<
telerik:RadComboBoxItem
runat
=
"server"
Text
=
"Manitoba"
Value
=
"MB"
/>
<
telerik:RadComboBoxItem
runat
=
"server"
Text
=
"Yukon"
Value
=
"YT"
/>
<
telerik:RadComboBoxItem
runat
=
"server"
Text
=
"Nuvanut"
Value
=
"NU"
/>
</
Items
>
</
telerik:RadComboBox
>
<
asp:PlaceHolder
ID
=
"phPPSAControl"
runat
=
"server"
></
asp:PlaceHolder
>
/// And the C# Code behind
private string _currentProvince = "";
protected void Page_PreInit(object sender, EventArgs e)
{
MasterPage master = this.Master;
_currentProvince = GetCurrentOperatingProvince(IsPostBack);
cmbProvince.SelectedValue = _currentProvince;
txtReferenceNo.Text = "TECHLOS" + DateTime.Now.ToString("MMddyyyy-HHMMss");
//Reload Dynamic Control on Every Page Creation
LoadDetailControl();
}
/// <
summary
>
/// Handles the SelectedIndexChanged event of the cmbProvince control.
/// </
summary
>
/// <
param
name
=
"sender"
>The source of the event.</
param
>
/// <
param
name
=
"e"
>The <
see
cref
=
"Telerik.Web.UI.RadComboBoxSelectedIndexChangedEventArgs"
/> instance containing the event data.</
param
>
protected void cmbProvince_SelectedIndexChanged(object sender, RadComboBoxSelectedIndexChangedEventArgs e)
{
phPPSAControl.Controls.Clear();
_currentProvince = e.Value;
LoadDetailControl();
}
/// <
summary
>
/// Loads the detail control based on _currentProvince
/// </
summary
>
private void LoadDetailControl()
{
UserControl ucPPSAControl = (UserControl)LoadControl(GetUserControlPath(_currentProvince));
IPPSAView provView = ucPPSAControl as IPPSAView;
ApplicationContext.TargetProvince = _currentProvince;
PPSAPresenter presenter = new PPSAPresenter(provView, ApplicationContext);
provView.AttachPresenter(presenter, cmbProvince.SelectedValue, txtReferenceNo.Text);
phPPSAControl.Controls.Add(ucPPSAControl);
}
In each UC by province, it has a Search button with an OnClick Event. The first time I land on the default province, the Search button works as expected and fires the OnClick and the Event Handler Search_Click is ran.
Below is that of a typical UC for each province
<
telerik:RadButton
ID
=
"btnSearch"
runat
=
"server"
Text
=
"Search"
OnClick
=
"Search_OnClick"
>
</
telerik:RadButton
>
/// <
summary
>
/// Handles the OnClick event of the Search control.
/// </
summary
>
/// <
param
name
=
"sender"
>The source of the event.</
param
>
/// <
param
name
=
"e"
>The <
see
cref
=
"System.EventArgs"
/> instance containing the event data.</
param
>
protected void Search_OnClick(object sender, EventArgs e)
{
if (isValidSearchRequest())
{
DisplayResultsFromResponse(presenter.Search());
}
else
{
phResponse.Controls.Add(new LiteralControl(string.Format("<
span
style
=
'color:red'
>Invalid Search Request</
span
>")));
}
}
Now when I change the province to "ON" ( or any other province has the same behaviour), When I click on the Search Button on the newly generated UC , it only posts back without triggering the OnClick Event. Clicking Twice , does the same thing... and on the 3rd time, It does trigger the OnClick... and ran as normal!!!
The OnClick only occurs the first time I Load the first control and the minute I change the province, so a Post back to refresh the new View with a new Search Button, the latter when clicked doesn't trigger the Search_OnClick() but rather do a post back... Clicking again will post back again and finally a 3rd time, gets it to call this function ...