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

ajaxRequestWithTarget doing full postback

4 Answers 183 Views
Ajax
This is a migrated thread and some comments may be shown as answers.
Keith Morgan
Top achievements
Rank 1
Keith Morgan asked on 25 May 2010, 04:12 PM
My problem is my call to ajaxRequestWithTarget is doing a repost when I expect an ajax update.

I have a master page containing RadAjaxManager, and a content page containing two user controls, uc1 and uc2.

uc1 has a ajax-enabled asp:Button and a text box inside an asp:Panel. Clicking on uc1.Button1 does the right thing, an ajax update without a full page refresh. My Page_Load:

protected void Page_Load(object sender, EventArgs e) 
  RadAjaxManager radAjaxManager = RadAjaxManager.GetCurrent(Page); 
  radAjaxManager.AjaxSettings.AddAjaxSetting(uc1.FindControl("Button1"),  uc1.FindControl("Panel1"), null); 


I have a list box in uc2. When an item in uc2.List1 is clicked, I want to simulate clicking uc1.Button1. My javascript code looks something like:

var ajaxManager = $find('<%= RadAjaxManager.GetCurrent(Page).ClientID %>'); 
var buttonID = '<%= GetUc1Control("Button1").UniqueID %>'
ajaxManager.ajaxRequestWithTarget(buttonID, ''); 


The call to ajaxRequestWithTarget is correctly updating the content of uc1, but it is causing a refresh of the entire page. How do I fix this problem?

4 Answers, 1 is accepted

Sort by
0
Nikolay Rusev
Telerik team
answered on 27 May 2010, 11:12 AM
Hello Keith,

The issue is caused due to ClientIDMode set to Static. When placed inside naming container with such client id mode, PageRequestManager fails to provide postback element.

Regards,
Nikolay
the Telerik team

Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
0
Keith Morgan
Top achievements
Rank 1
answered on 28 May 2010, 12:20 PM
Thanks for your response.

We use ClientIDMode="Static" many places for CSS reasons. In general, which control(s) specifically can't have static id's, and what ClientIDMode modes are allowed for those controls? I am asking this because in the example project I sent you, changing Panel1 to have default ClientIDMode value fixed the update problem, but in my real application changing the ClientIDMode of the enclosing panel did not fix the problem.

Is this aspect of Ajax routing considered a bug or a feature?

Thanks.

0
Nikolay Rusev
Telerik team
answered on 31 May 2010, 01:21 PM
Hello Keith,

The issue can be easily replicated without any of RadControls for ASP.NET AJAX. Simply place the following code inside some INamingContainer(UserControl for example)

01.<asp:UpdatePanel runat="server" ID="UP1" UpdateMode="Conditional">
02.    <ContentTemplate>
03.        <asp:Button runat="server" Text="Submit" ID="MyButton" ClientIDMode="Static" UseSubmitBehavior="false" />
04.    </ContentTemplate>
05.    <Triggers>
06.        <asp:AsyncPostBackTrigger ControlID="MyButton" />
07.    </Triggers>
08.</asp:UpdatePanel>
09.<script type="text/javascript">
10.    Sys.WebForms.PageRequestManager.getInstance().add_initializeRequest(function (sender, args)
11.    {
12.        alert(args.get_postBackElement().id);
13.    })
14.</script>

and place the UserControl on the page. When initializeRequest is triggered there is no postback element provided by PageRequestManager.

In general I would suggest you to not set such ID mode on Button type controls that might be triggers on UpdatePanel or bound controls. You can find more details regarding ClientIDMode on following article:
http://msdn.microsoft.com/en-us/library/1d04y8ss.aspx

Regards,
Nikolay
the Telerik team

Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
0
Keith Morgan
Top achievements
Rank 1
answered on 01 Jun 2010, 03:06 PM
I was able to solve my problem by removing 'ClientIDMode="Static"' from both the enclosing asp:Panel and the asp:Button. All of the other controls in the panel still retain the static client id mode with no problem.
Tags
Ajax
Asked by
Keith Morgan
Top achievements
Rank 1
Answers by
Nikolay Rusev
Telerik team
Keith Morgan
Top achievements
Rank 1
Share this question
or