• Toll-free  888-665-8637
  • International  +1 717-220-0012
Welcome Guest! To enable all features please Login or Register.

Notification

Icon
Error

2 Pages<12
Cliff
#21 Posted : Friday, September 7, 2007 5:47:32 PM(UTC)
Cliff

Rank: Member

Joined: 5/24/2004(UTC)
Posts: 4,147

Thanks, I'll keep that in mind. Always curious. :)

Are there any decent resources for understanding how Anthem works and how to keep it from undoing any extra script that I write? For example, I need to add a class via js to all of my labels on domready (based on certain criteria), but once one of those labels is clicked, the classes go away.
Andy Miller
#22 Posted : Friday, September 7, 2007 6:52:30 PM(UTC)
Andy Miller

Rank: Member

Joined: 11/5/2003(UTC)
Posts: 2,136

Was thanked: 1 time(s) in 1 post(s)
There are a couple of Anthem articles, but I can't remember where (CodeProject may have one). In theory, Anthem is very straightforward: to Ajaxify an ASP.NET web control (i.e. Label or TextBox), you just substitute the Anthem version. For example, if you want to turn an ASP.NET Button postback into an Ajax callback, just replace <asp:Button> with <anthem:Button>.

Not all Anthem controls make callbacks (or postbacks), but all Anthem controls are updatable. That means all Anthem controls can be updated on the client when the callback response is parsed. To perform this trick, all Anthem controls encase the underlying ASP.NET control elements inside of a <div> (for controls that normally render block elements) or a <span> with a special id. If the callback response includes an updated version of underlying control, then the entire innerHTML of the wrapper <div> or <span> is replaced. That is why you are loosing your client side updates.

I don't have an easy answer for you. Obviously, you could just avoid updating Anthem controls with client-side script, but I'm sure you will run into circumstances when you want to update the control from both the server and the client. In those cases I think you will need to reconcile the changes on the server.

For example, in my Shipping Rate Provider Suite I use a combination of Anthem and Yahoo! User Interface controls. In some situations I need to reconcile changes that were made via YUI with changes that I am making on the server. When that happens, I add code to the server-side that re-applies the client-side changes. I do this using Anthem.Manager.RegisterClientScript methods or Anthem.Manager.AddScriptForClientEval. These methods inject javascript into the callback response which are evaluated on the client when the callback returns to the client.

There are other .NET Ajax libraries that do not replace the entire control HTML during an update. They just update the properties that were changed during the callback. Those libraries would probably work better for you since they would not stomp on your other client-side changes (or at least not as often). I'm pretty sure MS Ajax rewrites the entire control, just like Anthem, so it is not such as good solution for you.
Andy Miller
Structured Solutions

Shipper 3 - High Velocity Shipment Processing
Cliff
#23 Posted : Friday, September 7, 2007 7:06:13 PM(UTC)
Cliff

Rank: Member

Joined: 5/24/2004(UTC)
Posts: 4,147

That's what I needed to know, thanks again, Andy.
Cliff
#24 Posted : Saturday, September 8, 2007 3:35:01 PM(UTC)
Cliff

Rank: Member

Joined: 5/24/2004(UTC)
Posts: 4,147

Sorry to keep asking questions about this, but this one really does have me stumped.

I'm trying to change the class on the radio button span when it is selected, and it seems simple enough in the code. But it only works on the page load, and doesn't change via Anthem when a new radio button is selected. Is there a trick to getting the radio button to AutoUpdateAfterCallBack (which is set to true in the anthem:RadioButtonList)?
Andy Miller
#25 Posted : Saturday, September 8, 2007 5:21:33 PM(UTC)
Andy Miller

Rank: Member

Joined: 11/5/2003(UTC)
Posts: 2,136

Was thanked: 1 time(s) in 1 post(s)
Can you send/attach what you have?
Andy Miller
Structured Solutions

Shipper 3 - High Velocity Shipment Processing
Cliff
#26 Posted : Sunday, September 9, 2007 3:10:19 AM(UTC)
Cliff

Rank: Member

Joined: 5/24/2004(UTC)
Posts: 4,147

Sure thing, attached.

I've tried it a few different ways with the same result. This is the bit I'm using right now:
Code:

If item.Value = Me.ChoiceRadioButtonList.SelectedValue Then
item.Attributes("class") = "swatch selected"
Else
item.Attributes("class") = "swatch"
End If
File Attachment(s):
SwatchImageList.zip (7kb) downloaded 225 time(s).

You cannot view/download attachments. Try to login or register.
Andy Miller
#27 Posted : Sunday, September 9, 2007 3:55:47 AM(UTC)
Andy Miller

Rank: Member

Joined: 11/5/2003(UTC)
Posts: 2,136

Was thanked: 1 time(s) in 1 post(s)
The problem is that the Display method is called before the value is selected by ASP.NET. So I changed your code a little bit. I moved the item.Attributes("class") = "xxx" code to a separate method called SetCssClasses. Then I call that once when the control is loaded (see InitializeDisplay) and again after the selected index changes (see ChoiceList_SelectedIndexChanged).
File Attachment(s):
View.ascx.vb (3kb) downloaded 228 time(s).

You cannot view/download attachments. Try to login or register.
Andy Miller
Structured Solutions

Shipper 3 - High Velocity Shipment Processing
Cliff
#28 Posted : Sunday, September 9, 2007 4:26:53 AM(UTC)
Cliff

Rank: Member

Joined: 5/24/2004(UTC)
Posts: 4,147

Brilliant, thank you so much!

Man, how many beers are we up to after all these years? It might be cheaper just to buy you Bridgeport Brewery. :)
Andy Miller
#29 Posted : Sunday, September 9, 2007 7:22:24 PM(UTC)
Andy Miller

Rank: Member

Joined: 11/5/2003(UTC)
Posts: 2,136

Was thanked: 1 time(s) in 1 post(s)
At the risk of pushing this too far, I tweaked View.ascx one more time. I think this is a better model for any future variations. Instead of setting the CSS classes in multiple places, I moved that code to OnPreRender.


Every ASP.NET page and user control has a "lifecycle"...a predictable sequence of steps. The step called PreRender is executed immediately before the control is rendered, after the control values have been set and the events have been raised, etc. Normally, nothing is actually done in the PreRender step. But if you write a method called OnPreRender, ASP.NET will call it. I like to use OnPreRender to make visual changes to the control, like setting the CSS class.



The other change I made was to View.ascx. Several of the Anthem controls will automatically update themselves when something important happens. The RadioButtonList will update itself if the selected index changes. That means you do not need to add AutoUpdateAfterCallBack="true". And if you remove it, then other, unrelated callbacks responses, will be smaller because they will not include this RadioButtonList.
File Attachment(s):
View.ascx (1kb) downloaded 261 time(s).

You cannot view/download attachments. Try to login or register.
Andy Miller
Structured Solutions

Shipper 3 - High Velocity Shipment Processing
Cliff
#30 Posted : Tuesday, September 11, 2007 1:03:28 PM(UTC)
Cliff

Rank: Member

Joined: 5/24/2004(UTC)
Posts: 4,147

Excellent, thanks again. This has really turned into something usable, i.e., click the swatch and add to cart. The way it should be. :)
2 Pages<12
Forum Jump  
You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot delete your posts in this forum.
You cannot edit your posts in this forum.
You cannot create polls in this forum.
You cannot vote in polls in this forum.

©2024 Develisys. All rights reserved.
  • Toll-free  888-665-8637
  • International  +1 717-220-0012