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

Forcing refresh by Javascript

3 Answers 423 Views
Ajax
This is a migrated thread and some comments may be shown as answers.
Emir Prcic
Top achievements
Rank 1
Emir Prcic asked on 24 Jun 2011, 10:35 AM
Hy
I do have the following scenario: I am having a Radgrid inside a visual Webpart which is using AJAX. The Radgrid with the Loadingpanel exists within the UserAdministrationUserControl, the RadAjaxmanager is added to the UserAdministrationWebpart.cs by following code:

protected override void OnInit(EventArgs e)
{
    base.OnInit(e);
    ajaxmgr = new RadAjaxManager();
    ajaxmgr.AjaxRequest += new RadAjaxControl.AjaxRequestDelegate(AjaxManager_AjaxRequest);
 
    Page.Items.Add(typeof(RadAjaxManager), ajaxmgr);
    Page.Form.Controls.AddAt(0, ajaxmgr);
 
}
 
protected override void CreateChildControls()
{
    Control control = Page.LoadControl(_ascxPath);
    Controls.Add(control);
    RadGrid panel = control.FindControl("RadGrid1") as RadGrid;
    RadAjaxLoadingPanel loadingPanel = control.FindControl("RadAjaxLoadingPanel1") as RadAjaxLoadingPanel;
    ajaxmgr.AjaxSettings.AddAjaxSetting(panel, panel, loadingPanel);
}

So far it works quite well. However I have the scenario, the Edit-Button of the Radgrid opens a ModalDialogPopup for editing the selected User. When editing is finished and the ModalDialog is closed, the Radgrid should be reloaded/refreshed. This is possible by a javascript function, which is called after closing the modaldialog by a callback. And here is my problem.

The Callback-function should do just the following:
$find("<%= RadAjaxManager1.ClientID %>").ajaxRequest("Rebind");


But of course that isn´t possible as the RadAjaxmanager doesn´t exist in the UserControl, where the Javascript and the other controls are.

I´ve tried giving the RadAjaxmanager an Id and finding it by:

$find('<%# this.Page.Forms.FindControl("MyRadAjaxManager").ClientID %>').ajaxRequest("Rebind");

But that doesn´t work, the Control cannot be found (in the console it returns the function as "$find('').ajaxRequest("Rebind") ).

While Debugging, I´ve found out, that the AjaxManager always gets the same ClientID, so the following is starting a refresh (i didn´t set the controls ID in that case):

$find("ctl00_ctl44").ajaxRequest("Rebind");

However, I do not want to hardcode the Controls ClientID. Besides, altough it is updating the Radgrid in that case, the LoadingPanel does not show up by using that Javascript (it works without a harm in all other cases eg. paging). And therefore it is not very userfriendly.

Any Help and suggestions will be very appreciated

Regards

3 Answers, 1 is accepted

Sort by
0
Genti
Telerik team
answered on 24 Jun 2011, 06:22 PM
Hello Emir Prcic,

Thank you for contacting us.
I see that you are declaring an instance of the ajax manager programmatically in the code-behind.
I also noticed that you are trying to reference the ajax manger by id in the design view.
However, I do not see a definition of the ID of the ajax manager that you are trying to reference.
I would suggest that you define the ajax manager in the following way:
RadAjaxManager manager = new RadAjaxManager();
manager.ID = "RadAjaxManager1";
this.Page.Form.Controls.Add(manager);
This way, you would not only have reference to the ajax manger, but also its viewstate is going to be loaded successfully on each postback.
So, to reference it now you would need:
var ajaxManager = $find("<%= RadAjaxManager.GetCurrent(Page).ClientID %>");

Additionally, you can refer to this help topic for more information on RadAjaxManager programmatic creation.

Let me know if this helps.

All the best,
Genti
the Telerik team

Browse the vast support resources we have to jump start your development with RadControls for ASP.NET AJAX. See how to integrate our AJAX controls seamlessly in SharePoint 2007/2010 visiting our common SharePoint portal.

0
Emir Prcic
Top achievements
Rank 1
answered on 27 Jun 2011, 07:26 AM
No, sorry, it doesn work,

I am getting the error "$find('') is null" in the javascript console.

Currently I´ve defined it in the following way:

ajaxmgr = new RadAjaxManager();
ajaxmgr.AjaxRequest += new RadAjaxControl.AjaxRequestDelegate(AjaxManager_AjaxRequest);
ajaxmgr.ID = "MyAjaxManager";
Page.Items.Add(typeof(RadAjaxManager), ajaxmgr);
Page.Form.Controls.AddAt(0, ajaxmgr);

and Javascript is:
$find('<%# RadAjaxManager.GetCurrent(Page).ClientID %>').ajaxRequest("Rebind");

(declaring it with "<%=" results in an error when calling the page ("

The Controls collection cannot be modified because the control contains code blocks (i.e. <% ... %>).

").

Maybe it has something to do with the fact, that the javascript exists and is called in the Usercontrol and the Radajaxmanager is defined and added to the WebPart.cs-File?
0
Emir Prcic
Top achievements
Rank 1
answered on 27 Jun 2011, 08:01 AM
It is working when using the following Javascript inside a RadCodeblock (the "normal" javascript definition results in the error mentioned above)

<telerik:RadCodeBlock ID="RadCodeBlock1" runat="server">
    <script type="text/javascript">
        function vPUserEditCallback(dialogResult, returnValue) {
            $find("<%= RadAjaxManager.GetCurrent(Page).ClientID %>").ajaxRequestWithTarget("<%=RadGrid1.ClientID %>", "Rebind");
        }
    </script>
</telerik:RadCodeBlock>

The ajaxRequestWithTarget is needed to force the loadingpanel to show up, with normal "ajaxRequest" it is not showing up, altough the Radgrid is getting updated.

Tags
Ajax
Asked by
Emir Prcic
Top achievements
Rank 1
Answers by
Genti
Telerik team
Emir Prcic
Top achievements
Rank 1
Share this question
or