Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/333.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# updatel面板内的jQuery评级插件_C#_Asp.net_Jquery_Asp.net Ajax_Updatepanel - Fatal编程技术网

C# updatel面板内的jQuery评级插件

C# updatel面板内的jQuery评级插件,c#,asp.net,jquery,asp.net-ajax,updatepanel,C#,Asp.net,Jquery,Asp.net Ajax,Updatepanel,我在asp:update面板中的asp:listview中使用jQuery评级插件。下面是单击评级星星时调用的函数 function DisplayRatings() { $('DIV.ratingBar').each(function() { var id = $(this).attr('id'); var count = $(this).attr('rel');

我在asp:update面板中的asp:listview中使用jQuery评级插件。下面是单击评级星星时调用的函数

function DisplayRatings() {            
            $('DIV.ratingBar').each(function() {
                var id = $(this).attr('id');
                var count = $(this).attr('rel');
                $('#' + id).raty({
                    showCancel: false,
                    readOnly: false,
                    showHalf: true,
                    start: count,
                    onClick: function(score) {                    
                      // I have to pass the score and ID to server side                    
                    }
                });
            });
        }
现在,我必须将“score”和“ID”传递给服务器端,并调用一个方法,该方法重新绑定listview并在屏幕上更新评级,而无需屏幕刷新。
请建议如何执行此操作。(我不能使用ajax工具包评级,因为它不支持半星评级)

要将数据传递到服务器,只需将其存储在隐藏的表单字段中(在UpdatePanel中):

这将导致对
UpdatePanel
进行异步更新,就像用户单击绑定的提交控件一样

请注意,如果jQuery控件本身位于
UpdatePanel
中,则必须在异步回发后重新配置它,因为其效果就好像页面已被重新加载一样。但是,您在
$(document).ready()
中运行的任何javascript代码在异步回发后都不会运行,因为整个页面实际上没有重新加载

理想情况下,将分级控制保持在更新面板之外,因为您可能不希望它因其启动的事件而改变。如果由于某种原因无法实现此功能,或者您只需要在第一次看到它时以动态方式对其进行配置,则在页面刷新结束时添加一个钩子:

// Page startup script - this adds a hook after an update panel is refreshed
Sys.WebForms.PageRequestManager.getInstance().add_pageLoaded(onRefresh);

function onRefresh(sender, args) {
    // You can try to check which panel was updated
    var panelsUpdated  = args.get_panelsUpdated();
    var panelsCreated = args.get_panelsCreated();
    // but usually it's easier to just track the state of your jquery stuff
    if (my_jquery_thing_is_visible &&
        my_indicator_that_it_has_already_been_configured===false) {
        configureJqueryThing();
    }
}

通过使用jQuery和AJAX解决了这个问题

aspx

功能保存等级(id,分数){
变量参数=“{linkID:“+id+”,ratingVal:“+score+”}”;
$.ajax({ 类型:“POST”, url:“page.aspx/updates”, 数据:params, contentType:“应用程序/json;字符集=utf-8”, 数据类型:“json” }); }

aspx.cs

[System.Web.Services.WebMethod] 公共静态无效更新(字符串linkID,int ratingVal) { //要更新到db的代码 }

$('#score').val(score);
$('#id').val(id);
__doPostBack('UpdatePanelID', '') 
// Page startup script - this adds a hook after an update panel is refreshed
Sys.WebForms.PageRequestManager.getInstance().add_pageLoaded(onRefresh);

function onRefresh(sender, args) {
    // You can try to check which panel was updated
    var panelsUpdated  = args.get_panelsUpdated();
    var panelsCreated = args.get_panelsCreated();
    // but usually it's easier to just track the state of your jquery stuff
    if (my_jquery_thing_is_visible &&
        my_indicator_that_it_has_already_been_configured===false) {
        configureJqueryThing();
    }
}