rating.aspx.cs

来自「一个包含AJAX所有功能的示例网站以及源代码,非常好学习!」· CS 代码 · 共 69 行

CS
69
字号
// (c) Copyright Microsoft Corporation.
// This source is subject to the Microsoft Permissive License.
// See http://www.microsoft.com/resources/sharedsource/licensingbasics/sharedsourcelicenses.mspx.
// All other rights reserved.


using System;
using System.Threading;
using System.Web.UI.WebControls;
using AjaxControlToolkit;

public partial class Rating_Rating : CommonPage
{
    /// <summary>
    /// Set the alignment of the stars in the rating control
    /// </summary>
    /// <param name="e">argument</param>
    protected override void OnLoad(EventArgs e)
    {
        base.OnLoad(e);
        ThaiRating.RatingAlign = (lstAlign.SelectedIndex == 1) ?
                Orientation.Vertical :
                Orientation.Horizontal;
        ThaiRating.RatingDirection = (lstDirection.SelectedIndex == 1) ?
                RatingDirection.RightToLeftBottomToTop :
                RatingDirection.LeftToRightTopToBottom;
    }

    /// <summary>
    /// Updates the label with how spicy the user likes their Thai food
    /// </summary>
    /// <param name="sender">source</param>
    /// <param name="e">argument</param>
    protected void Submit_Click(object sender, EventArgs e)
    {
        string howSpicy = "[unknown]";
        switch (ThaiRating.CurrentRating)
        {
            case 1 :
                howSpicy = "bland";
                break;
            case 2 :
                howSpicy = "mild";
                break;
            case 3 :
                howSpicy = "spicy";
                break;
            case 4:
                howSpicy = "scorching hot";
                break;
            case 5:
                howSpicy = "tongue melting";
                break;
        }
        lblResponse.Text = "You prefer Thai food that is <b>" + howSpicy + "</b>.";
    }

    /// <summary>
    /// Run custom code when the user rates something and then return a custom string
    /// to the JavaScript client
    /// </summary>
    /// <param name="sender">Rating control</param>
    /// <param name="e">RatingEventArgs</param>
    protected void ThaiRating_Changed(object sender, RatingEventArgs e)
    {
        Thread.Sleep(400);        
        e.CallbackResult = "Update done. Value = " + e.Value + " Tag = " + e.Tag;
    }
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?