I have a user control with a RadGrid and an Edit button in it. Clicking the Edit button retrieves the primary key for the selected row within the RadGrid and opens a RadWindow passing the primary key to the page opened in the window using a Query String.
Then I have a javascript routine that handles the Window close and does a Rebind on the RadGrid to refresh it with the latest values. I use the argument from the Window to get the primary key again and select the corresponding row in the RadGrid. This is done by calling
var
ajaxManager = $find("<%= this.Page.AjaxManager.ClientID %>");
ajaxManager.ajaxRequestWithTarget('<%= Button_EditEntry.UniqueID %>', oWnd.argument);
The trouble is, this works fine within a page, but within a UserControl I seem to be faced with a dilema:
To retrieve the argument passed in the Ajax Request, I have to implement a RaisePostBackEvent method in my code-behind. For a page, this is a simple matter of overriding the page's implementation of this. For a UserControl, I have to implement IPostBackEventHandler. According to the documentation, to ensure that my RaisePostBackEvent function gets called, I have to call ajaxRequestWithTarget using the UniqueID of the UserControl itself instead of the button, but if I do that, all the controls within the UserControl get updated during the Ajax Request instead of just those controls that Button_EditEntry should affect.
Within a UserControl, how can I initiate an Ajax call on the client side, retrieve the argument on the server side, and limit the controls that are updated to one or two instead of the entire UserControl?
Jeff
9 Answers, 1 is accepted
You can't do this, because it seems that the MS guys have forgotten that you could have a scenario where a component that does not render any html can actually submit the page. This way if you specify the user control as initiator it would throw "Sys.ArgumentNullException: Value cannot be null. Parameter name: postBackElement".
To avoid that you could ignore RaisePostBackEvent and use the AjaxManager to handle this scenario like that:
protected void Page_Load(object sender, EventArgs e)
{
RadAjaxManager ajaxManager = RadAjaxManager.GetCurrent(Page);
ajaxManager.AjaxRequest += new RadAjaxControl.AjaxRequestDelegate(ajaxManager_AjaxRequest);
}
void ajaxManager_AjaxRequest(object sender, AjaxRequestEventArgs e)
{
ScriptManager.GetCurrent(Page).AsyncPostBackSourceElementID; //you get the initiator here or in the e.Args where you have passed the arg as part of the AjaxRequest()
}
All the best,
Steve
the Telerik team
Instantly find answers to your questions at the new Telerik Support Center
I'm faced with the same dilemma.
In a usercontrol:
If I have a contextmenu on a treeview, and then when a menuitem is clicked, i display a radprompt, the user enters a value and I initiate an ajaxrequest to the server with the foldernode. How would i update the treeview on the ajax_request event? If i add a arbitrary node it doesn't get reflected in the treeview, even though i have a radajaxmanagerproxy with an ajaxsetting with treeview.
You could suggest using the RadAjaxManager.GetCurrent(Page) method in order to get the manager and ajaxify the TreeView in the UC instead of using RadAjaxManagerProxy control. In this way you will also be able to use the RadAjaxManager functionality (like ResponseScripts collection, ajaxRequest function). More information on similar scenario could be found in this help topic.
All the best,
Maria Ilieva
the Telerik team
Check out Telerik Trainer, the state of the art learning tool for Telerik products.
I think you misunderstood my question. I have the exact same scenario as the guy who started this post, and I'm already using the approach Steve from telerik suggested. However,
in the following method:
void ajaxManager_AjaxRequest(object sender, AjaxRequestEventArgs e)
{
ScriptManager.GetCurrent(Page).AsyncPostBackSourceElementID;
MyTreeView.Nodes.Add(new RadTreeNode("test", "test"));
}
If i add a node like the above method, my tree is not updated with the changes when the request finishes. (remember that this is in a usercontrol like the example in this thread).
Thanks
Will it be convenient for you to open a regular support ticket and send us small runnable application, which replicates the described behaviour? We will test it locally and do our best to provided accurate solution.
Greetings,
Maria Ilieva
the Telerik team
Check out Telerik Trainer, the state of the art learning tool for Telerik products.
C#
protected void Page_Load(object sender, EventArgs e)
{
RadAjaxManager manager = RadAjaxManager.GetCurrent(Page);
manager.AjaxRequest += new RadAjaxControl.AjaxRequestDelegate(ajaxManager_AjaxRequest);
}
public void ajaxManager_AjaxRequest(object sender, AjaxRequestEventArgs e)
{
calendarPopup.ShowStuff(e.Argument); //call method on user control
}
JavaScript
$find('<%# RadAjaxManager.GetCurrent(Page).ClientID %>').ajaxRequestWithTarget('<%# calendarPopupContainer.ClientID %>', s);
//$find('<%# RadAjaxManager.GetCurrent(Page).ClientID %>').ajaxRequest(s);
When I use the first JavaScript with ajaxRequestWithTarget(), the content area in question is re-drawn (I'm printing out the Time and it changes whenever it reloads), but the AjaxRequestDelegate never executes in this case.
If I use ajaxRequest(), the AjaxRequestDelegate is executed, but my content area isn't re-drawn.
Help?
Thanks in advance!
Rebecca