Wednesday, March 28, 2012

Multiple rating controls on one page malfunction

Hi,

When I put multiple rating controls on a page, only the first one works. The others act as if they has set ReadOnly = true. I've tried putting them on different pages, inside different update panels, inside the same update panel, outside update panels, setting ReadOnly = false for each one, setting the same OnChanged function, setting different OnChanged functions. Same thing every time. The first one works just fine and calls its OnChanged function. All the rest don't respond to mouseOver, and don't call their OnChanged. But their 1-5 tooltips do pop up, so they are breathing. Please help!

Any thoughts? Am I the only one this happens to? I'm new to ajax, so please point out the obvious...

I have the Script Manager on a master page. I set the .css to the one given in AjaxControlToolkit\SampleWebSite for simplicity. I also tacked ajax onto this project by copying web.config info ala joe's video- did I maybe miss something there?

Here's the code-

<asp:UpdatePanel id="upFilter1" runat="server">
<contenttemplate>
<cc1:Rating ID="rateFilter1" runat="server"
BehaviorID="RatingBehavior1"
CurrentRating="2"
MaxRating="5"
StarCssClass="ratingStar"
WaitingStarCssClass="savedRatingStar"
FilledStarCssClass="filledRatingStar"
EmptyStarCssClass="emptyRatingStar"
OnChanged="ContentFilterChanged"
style="float: left;" Height="6px" Width="65px" />
</contenttemplate>
</asp:UpdatePanel
<asp:UpdatePanel id="upFilter2" runat="server">
<contenttemplate>
<cc1:Rating ID="rateFilter2" runat="server"
BehaviorID="RatingBehavior1"
CurrentRating="2"
MaxRating="5"
StarCssClass="ratingStar"
WaitingStarCssClass="savedRatingStar"
FilledStarCssClass="filledRatingStar"
EmptyStarCssClass="emptyRatingStar"
OnChanged="ContentFilterChanged1"
style="float: left;" Height="6px" Width="65px" ReadOnly=false />
</contenttemplate>
</asp:UpdatePanel>


Again, first one works fine, second one doesn't respond.


I think it's because your BehaviorID IDs are the same. I'm having the same problem, but I'm generating my Ratings in a while loop, so cannot change them.


Anyone got any idea how I give each Rating control a unique BehaviorID?


Yep, that did it. It works with the basic appearances- now to hook them up to actually function. If it changes the functionality I'll check back in.

What's wrong with the loop? Can't you just set

NextRating.BehaviorID = NextID

NextID += 1



I've since found that you don't use while loops to output multiple rows of returned data anymore. The new method is to use an ASP Repeater and bind it to a dataTable. This magically sorts the IDs out for you by itself.

No comments:

Post a Comment