![](/img/trans.png)
[英]How create an AjaxToolKit control, (rating), from code-behind in C#?
[英]handling multiple ajaxtoolkit rating control BehaviorID's on a single page
我有一個Webform,可以在其中動態加載Web用戶控件。 Web用戶控件中有一個轉發器控件,而在轉發器控件中,我有一個針對每個重復項的ajaxtoolkit評分控件,並且Web用戶控件可以根據需要在自身內部動態創建多次。 要處理選定的評分,我必須將BehaviorID與以下代碼一起使用:
<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>
問題是,當一次在窗體上出現多個評級控件時,只有第一個評級控件起作用,而其他評級被禁用。 如果我取出BehaviorID,則一切正常。
我的問題是,由於每個評分控件都需要這些項目,我該如何為多個BehaviorID和每個腳本編寫代碼?
這是通過執行以下操作來完成的:
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);
並在repeating_ItemDataBound中
rating.BehaviorID = "ratingControlBehavior" + pnt.eval_id.ToString();
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.