Search code examples
c#asp.netrating

handling multiple ajaxtoolkit rating control BehaviorID's on a single page


I have a webform which dynamically loads a web user control in it. Within the web user control is a repeater control and within the repeater control I have an ajaxtoolkit rating control for each repeating item, and the web user control can be dynamically created within it self as many times as needed. To handle the selected rating I have to use BehaviorID along with the following code:

<script type="text/javascript">
    function pageLoad() { $find("ratingControlBehavior").add_EndClientCallback(onClientCallBack); }
    function onClientCallBack(sender, eventArgs) {
        var htmlname = sender._callbackID.substring(0, sender._callbackID.lastIndexOf('$')) + '_hdrating';
        htmlname = htmlname.replace(/\$/g, '_')
        var hdctl = document.getElementById(htmlname);
        hdctl.value = eventArgs.get_CallbackResult(); 
    }
</script>

the issue is, when more than one rating control is on the form at once, only the first rating control works, the other ratings are disabled. If I take out the BehaviorID then all works fine.

My question is, how would I code for multiple BehaviorID's as well as the script for each, since I need these items for each rating control?


Solution

  • This was accomplished by doing the following:

        String scriptText = "";
        scriptText += "function pageLoad(){";
        foreach ( group.category.point item in tpnts )
        { scriptText += "     $find('ratingControlBehavior" + item.eval_id + "').add_EndClientCallback(onClientCallBack);"; }
        scriptText += "}";
        ClientScriptManager csm = ClientScript;
        csm.RegisterStartupScript(this.GetType(), "scriptonload", scriptText, true);
    

    and within the repeating_ItemDataBound

            rating.BehaviorID = "ratingControlBehavior" + pnt.eval_id.ToString();