I am needing that depending on a condition verified in the code behind, I update certain controls by ajax. I researched some ways and I believe that would solve, is to add AJAX settings dynamically. But still could not solve the problem.
I have based on this example http://demos.telerik.com/aspnet-ajax/ajax/examples/manager/dynamicajaxsettings/defaultcs.aspx
An example to demonstrate the problems that can not solve, basically a ComboBox that selects which of the divs should be updated:
That the error occurs:
Erro: Sys.InvalidOperationException: Could not find UpdatePanel with ID 'ctl00_MainContent_ctl00_MainContent_div_2Panel'. If it is being updated dynamically then it must be inside another UpdatePanel.
Arquivo-fonte: http://localhost:10677/Telerik.Web.UI.WebResource.axd?_.......
This occurs because the telerik previously did not know what I would update divs. So do not create the Panels.
If I add these tags, even if this case does not make sense. works because the telerik creates the Panels, but I think we can bring me some trouble in the future.
I think that's why the example of the telerik site works. (
Following the recommendation of the error, add RadAjaxPanels on divs:
But now another error occurs:
Erro: Sys.WebForms.PageRequestManagerServerErrorException: Object reference not set to an instance of an object.
Arquivo-fonte: http://localhost:10677/Telerik.Web.UI.WebResource.axd?_TSM_....
Searched these errors on the forums, but have not found a solution, can anyone help?
I have based on this example http://demos.telerik.com/aspnet-ajax/ajax/examples/manager/dynamicajaxsettings/defaultcs.aspx
An example to demonstrate the problems that can not solve, basically a ComboBox that selects which of the divs should be updated:
<
telerik:RadScriptManager
ID
=
"telerik_ajax_manager"
runat
=
"server"
OutputCompression
=
"Forced"
/>
<
telerik:RadAjaxLoadingPanel
ID
=
"ajax_Loaging_Panel"
Enabled
=
"true"
runat
=
"server"
MinDisplayTime
=
"1000"
BackColor
=
"#cccccc"
Transparency
=
"50"
/>
<
div
id
=
"div_1"
runat
=
"server"
>
<
asp:Label
ID
=
"lbl_1"
runat
=
"server"
Text
=
"Div 1"
></
asp:Label
>
<
br
/>
Update:
<
telerik:RadComboBox
ID
=
"cbx_update"
runat
=
"server"
>
<
Items
>
<
telerik:RadComboBoxItem
Value
=
"div_2"
Text
=
"Div 2"
/>
<
telerik:RadComboBoxItem
Value
=
"div_3"
Text
=
"Div 3"
/>
</
Items
>
</
telerik:RadComboBox
>
</
div
>
<
br
/>
<
div
id
=
"div_2"
runat
=
"server"
>
<
asp:Label
ID
=
"lbl_2"
runat
=
"server"
Text
=
"Div 2"
></
asp:Label
>
</
div
>
<
br
/>
<
div
id
=
"div_3"
runat
=
"server"
>
<
asp:Label
ID
=
"lbl_3"
runat
=
"server"
Text
=
"Div 3"
></
asp:Label
>
</
div
>
<
br
/>
<
telerik:RadButton
ID
=
"btn_submit"
runat
=
"server"
onclick
=
"btn_submit_Click"
Text
=
"Submit"
></
telerik:RadButton
>
<
telerik:RadAjaxManager
ID
=
"ajax_manager"
runat
=
"server"
DefaultLoadingPanelID
=
"ajax_Loaging_Panel"
>
<
AjaxSettings
>
<
telerik:AjaxSetting
AjaxControlID
=
"btn_submit"
>
<
UpdatedControls
>
<
telerik:AjaxUpdatedControl
ControlID
=
"div_1"
/>
</
UpdatedControls
>
</
telerik:AjaxSetting
>
</
AjaxSettings
>
</
telerik:RadAjaxManager
>
protected
void
btn_submit_Click(
object
sender, EventArgs e)
{
if
(cbx_update.SelectedValue ==
"div_2"
)
{
lbl_2.Text =
"Div 2 Updated"
;
ajax_manager.AjaxSettings.AddAjaxSetting(btn_submit, div_2);
}
else
{
lbl_3.Text =
"Div 3 Updated"
;
ajax_manager.AjaxSettings.AddAjaxSetting(btn_submit, div_3);
}
}
That the error occurs:
Erro: Sys.InvalidOperationException: Could not find UpdatePanel with ID 'ctl00_MainContent_ctl00_MainContent_div_2Panel'. If it is being updated dynamically then it must be inside another UpdatePanel.
Arquivo-fonte: http://localhost:10677/Telerik.Web.UI.WebResource.axd?_.......
This occurs because the telerik previously did not know what I would update divs. So do not create the Panels.
If I add these tags, even if this case does not make sense. works because the telerik creates the Panels, but I think we can bring me some trouble in the future.
<
telerik:AjaxSetting
AjaxControlID
=
"div_3"
>
<
UpdatedControls
>
<
telerik:AjaxUpdatedControl
ControlID
=
"div_2"
/>
<
telerik:AjaxUpdatedControl
ControlID
=
"div_3"
/>
</
UpdatedControls
>
</
telerik:AjaxSetting
>
I think that's why the example of the telerik site works. (
<telerik:AjaxUpdatedControl ControlID="DivExternalForm"
...)Following the recommendation of the error, add RadAjaxPanels on divs:
<
telerik:RadAjaxPanel
ID
=
"pnl_2"
runat
=
"server"
>
<
div
id
=
"div_2"
runat
=
"server"
>
<
asp:Label
ID
=
"lbl_2"
runat
=
"server"
Text
=
"Div 2"
></
asp:Label
>
</
div
>
</
telerik:RadAjaxPanel
>
<
br
/>
<
telerik:RadAjaxPanel
ID
=
"pnl_3"
runat
=
"server"
>
<
div
id
=
"div_3"
runat
=
"server"
>
<
asp:Label
ID
=
"lbl_3"
runat
=
"server"
Text
=
"Div 3"
></
asp:Label
>
</
div
>
</
telerik:RadAjaxPanel
>
protected
void
btn_submit_Click(
object
sender, EventArgs e)
{
if
(cbx_update.SelectedValue ==
"div_2"
)
{
lbl_2.Text =
"Div 2 Updated"
;
ajax_manager.AjaxSettings.AddAjaxSetting(btn_submit, pnl_2);
}
else
{
lbl_3.Text =
"Div 3 Updated"
;
ajax_manager.AjaxSettings.AddAjaxSetting(btn_submit, pnl_3);
}
}
But now another error occurs:
Erro: Sys.WebForms.PageRequestManagerServerErrorException: Object reference not set to an instance of an object.
Arquivo-fonte: http://localhost:10677/Telerik.Web.UI.WebResource.axd?_TSM_....
Searched these errors on the forums, but have not found a solution, can anyone help?