将Ajax星级评分值检索到Asp.net后端 [英] Retrieve Ajax star rating value to Asp.net backend

查看:87
本文介绍了将Ajax星级评分值检索到Asp.net后端的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是我在aspx页面中的评分控件。当用户单击星号时,我要更新label3。

This is my rating control in aspx page. When user click the star, i want to update the label3.

<style type="text/css">
    .Star {
        background-image: url(img/Star.gif);
        height: 17px;
        width: 17px;
    }

    .WaitingStar {
        background-image: url(img/WaitingStar.gif);
        height: 17px;
        width: 17px;
    }

    .FilledStar {
        background-image: url(img/FilledStar.gif);
        height: 17px;
        width: 17px;
    }
</style>
<div>

    <asp:ScriptManager ID="ScriptManager1" runat="server"></asp:ScriptManager>

    <asp:UpdatePanel ID="UpdatePanel1" runat="server">
        <ContentTemplate>
            <ajaxToolkit:Rating ID="Rating1" AutoPostBack="true" OnChanged="OnRatingChanged" runat="server"
                StarCssClass="Star" WaitingStarCssClass="WaitingStar" EmptyStarCssClass="Star" CurrentRating="2"
                FilledStarCssClass="FilledStar">
            </ajaxToolkit:Rating>
        </ContentTemplate>
    </asp:UpdatePanel>
    <asp:Label runat="server" ID="label3"></asp:Label>
    <asp:Label runat="server" ID="label4" Text="above"></asp:Label>
</div>

我尝试使用Rating1.CurrentRating.ToString()进行操作,但Label3上没有任何内容。

I tried out using Rating1.CurrentRating.ToString() but there is nothing on Label3.

protected void OnRatingChanged(object sender, RatingEventArgs e)
    {
        label3.Text = Rating1.CurrentRating.ToString();
    }

我的代码是错误的还是可以通过其他方式获取值?我打算从后端获取价值,因为稍后我会将其添加到数据库中。请帮忙。谢谢。

Is my code wrong or I can get the value in another way? I'm planning to get the value from backend because later I will add it into my database. Please help. Thank you.

推荐答案

我认为您正在寻找的是 OnClick()不是 OnChange(),因为当用户单击 Rate 控件并更改其要获得当前的等级时, Rate 控件的值并将其显示在标签中,顺便说一句,在对<$ c的属性进行任何考虑之前,您应该执行以下desc,

的操作$ c> UpdatePanel (例如 UpdateMode ChildrenAsTriggers ),您可以将它们设置为<$ c对于$code> UpdatePanel1 ,如果$ c> UpdateMode = Always ChildrenAsTriggers = true 仍然无效,请执行以下步骤:

I think what are you looking for is OnClick() not OnChange(), as when user click on Rate control and change it's rating value you want to get current value of Rate control and show it in a label, BTW you should do following below desc,
before doing anything think about the properties of UpdatePanel like UpdateMode and ChildrenAsTriggers that you can set them like UpdateMode="Always" ChildrenAsTriggers="true" for UpdatePanel1 if by setting them it still doesnt work do the below steps:

1-首先将标签控件移到 UpdatePanel ContentTemplate >

2-然后处理 ajaxToolkit:Rating
$的 Click()事件b $ b 3-最后,您必须在设计模式下具有以下内容:

1- Firstly move that label controls into the ContentTemplate of UpdatePanel
2- Then handle Click() event of ajaxToolkit:Rating
3- At the end you must have something like in design mode:

<asp:UpdatePanel ID="UpdatePanel1" runat="server">
    <ContentTemplate>
        <ajaxToolkit:Rating ID="Rating1" AutoPostBack="true" runat="server"
            StarCssClass="Star" WaitingStarCssClass="WaitingStar" EmptyStarCssClass="Star"
            FilledStarCssClass="FilledStar" OnChanged="OnRatingChanged" OnClick="Rating1_Click">
        </ajaxToolkit:Rating> 
        <asp:Label runat="server" ID="label3"></asp:Label>
        <asp:Label runat="server" ID="label4" Text="above"></asp:Label>
    </ContentTemplate>
</asp:UpdatePanel>

以及 Rating1_Click 后面的代码:

protected void Rating1_Click(object sender, RatingEventArgs e)
{
    label3.Text = Rating1.CurrentRating.ToString();
}

这就像一个护身符!!

this works like a charm!!!.

这篇关于将Ajax星级评分值检索到Asp.net后端的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆