Tuesday, 29 July 2014

How to use Rating OnChanged event in asp.net ajax

Ajax Rating – How to use OnChanged event in asp.net Rating

  1. <%@ Page Language=“C#” AutoEventWireup=“true” %>

  2. <%@ Register Assembly=“AjaxControlToolkit” Namespace=“AjaxControlToolkit” TagPrefix=“asp” %>

  3. <!DOCTYPE html PUBLIC “-//W3C//DTD XHTML 1.0 Transitional//EN” “http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd”>
  4. <script runat=“server”>
  5.     protected void Rating1_Changed(object sender, EventArgs e)
  6.     {
  7.         int ratingValue = Rating1.CurrentRating;
  8.         if (ratingValue <= 3)
  9.         {
  10.             Label1.ForeColor = System.Drawing.Color.Red;
  11.         }
  12.         else
  13.         {
  14.             Label1.ForeColor = System.Drawing.Color.Green;
  15.         }
  16.         Label1.Text = “You Rated: “ + ratingValue;
  17.     }
  18. </script>

  19. <html xmlns=“http://www.w3.org/1999/xhtml”>
  20. <head id=“Head1″ runat=“server”>
  21.     <title>Ajax Rating - How to use OnChanged event in asp.net Rating</title>
  22.     <style type=“text/css”>
  23.         .StarCss {
  24.             background-image: url(/Image/star.png);
  25.             height:24px;
  26.             width:24px;
  27.         }
  28.         .FilledStarCss {
  29.             background-image: url(/Image/filledstar.png);
  30.             height:24px;
  31.             width:24px;
  32.         }
  33.         .EmptyStarCss {
  34.             background-image: url(/Image/star.png);
  35.             height:24px;
  36.             width:24px;
  37.         }
  38.         .WaitingStarCss {
  39.             background-image: url(/Image/waitingstar.png);
  40.             height:24px;
  41.             width:24px;
  42.         }
  43.     </style>

  44. </head>
  45. <body>
  46.     <form id=“form1″ runat=“server”>
  47.     <div>
  48.         <h2 style=“color:DarkBlue; font-style:italic;”>
  49.             ASP.NET Ajax Rating - How to use OnChanged
  50.             <br /> event in asp.net Rating
  51.         </h2>
  52.         <hr width=“500″ align=“left” color=“LightBlue” />
  53.         <asp:ToolkitScriptManager ID=“ToolkitScriptManager1″ runat=“server”>
  54.         </asp:ToolkitScriptManager>
  55.         <table border=“0″ cellpadding=“4″ cellspacing=“4″>
  56.             <tr>
  57.                 <td>
  58.                     <asp:Image
  59.                         ID=“Image1″
  60.                         runat=“server”
  61.                         ImageUrl=“~/Image/RedBird.jpg”
  62.                         Height=“250″
  63.                         />
  64.                 </td>
  65.                 <td>
  66.                     <asp:Label
  67.                         ID=“Label1″
  68.                         runat=“server”
  69.                         Font-Size=“X-Large”
  70.                         Font-Italic=“true”
  71.                         Font-Names=“Comic Sans MS”
  72.                         >
  73.                     </asp:Label>
  74.                     <br /><br />
  75.                     <asp:Label
  76.                         ID=“Label2″
  77.                         runat=“server”
  78.                         ForeColor=“SandyBrown”
  79.                         Font-Size=“Large”
  80.                         Text=“Rate this image”
  81.                         >
  82.                     </asp:Label>
  83.                     <br />
  84.                     <asp:Rating
  85.                         ID=“Rating1″
  86.                         runat=“server”
  87.                         StarCssClass=“StarCss”
  88.                         FilledStarCssClass=“FilledStarCss”
  89.                         EmptyStarCssClass=“EmptyStarCss”
  90.                         WaitingStarCssClass=“WaitingStarCss”
  91.                         AutoPostBack=“true”
  92.                         OnChanged=“Rating1_Changed”
  93.                         >
  94.                     </asp:Rating>
  95.                 </td>
  96.             </tr>
  97.         </table>
  98.     </div>
  99.     </form>
  100. </body>
  101. </html>




No comments:

Post a Comment