AJAX - How to set the Text of a Literal control outside of the UpdatePanel?

A

Alan Silver

Hello,

I have just started using AJAX today, and I'm amazed at how easy it is!

Anyway, excitement aside, I have managed to convert an existing order
page to show the order total as the user changes values on the form
(quantity of items, delivery country, etc), and have an order summary,
which uses Literal controls to display the results.

The problem is that I would like the order summary information to be
outside of the UpdatePanel so it is further down the page, below the
Order button (asp:Button control) that submits the whole page. However,
if I move the Literal controls outside of the UpdatePanel, they don't
get updated by the AJAX code.

I can see two ways out of this, but I don't know how to do either!

1) Put the summary Literal controls in a second UpdatePanel, and set the
code to update that panel as well as the first.

2) Extend the existing UpdatePanel further down the page, but set the
Order button to do a normal page postback, not an AJAX one.

I don't know if either of these can be done, or how. Any help would be
greatly appreciated. TIA.
 
A

Alan Silver

Alan Silver said:
1) Put the summary Literal controls in a second UpdatePanel, and set
the code to update that panel as well as the first.

OK, figured this out in case it's useful to anyone else. I made a second
UpdatePanel, and added a trigger for one of the controls that fires the
AJAX calls. The second panel looks like this...

<asp:UpdatePanel ID="updOrderSummary" runat="server">
<ContentTemplate>
....Literal controls go here...
</ContentTemplate>
<Triggers>
<asp:AsyncPostBackTrigger ControlID="drpCountry" />
</Triggers>
</asp:UpdatePanel>

What I don't understand is why I only needed to add a trigger for the
one control, when the AJAX call is triggered by any one of a number of
controls on the page. It seems to worth though!

Anyone able to explain this last bit? TIA
 
?

=?ISO-8859-1?Q?G=F6ran_Andersson?=

Alan said:
OK, figured this out in case it's useful to anyone else. I made a second
UpdatePanel, and added a trigger for one of the controls that fires the
AJAX calls. The second panel looks like this...

<asp:UpdatePanel ID="updOrderSummary" runat="server">
<ContentTemplate>
...Literal controls go here...
</ContentTemplate>
<Triggers>
<asp:AsyncPostBackTrigger ControlID="drpCountry" />
</Triggers>
</asp:UpdatePanel>

What I don't understand is why I only needed to add a trigger for the
one control, when the AJAX call is triggered by any one of a number of
controls on the page. It seems to worth though!

Anyone able to explain this last bit? TIA

I don't think that you need any trigger at all. The UpdateMode of the
update panels is set to Always by default, which means that every update
panel on the page will be updated with every AJAX postback.

If you set the UpdateMode to Conditional, the udpate panel will only be
updated when there is a matching trigger, or if you call the Update
method for the update panel.
 
A

Alan Silver

Göran Andersson said:
I don't think that you need any trigger at all. The UpdateMode of the
update panels is set to Always by default, which means that every
update panel on the page will be updated with every AJAX postback.

Ah, that explains why it worked when I had only added one trigger.

Thanks for the clarification. I must say that I found AJAX amazingly
easy to get going, but obviously I am far from understanding all the
details yet.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,968
Messages
2,570,150
Members
46,697
Latest member
AugustNabo

Latest Threads

Top