The Poll based on Ajax -- Koma
aspx( js included)
1<%@ Page language="c#" Codebehind="vote.aspx.cs" AutoEventWireup="false" Inherits="vote_ajax.vote" %>
2<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" >
3<HTML>
4 <HEAD>
5 <title>WebForm1</title>
6 <meta name="GENERATOR" Content="Microsoft Visual Studio .NET 7.1">
7 <meta name="CODE_LANGUAGE" Content="C#">
8 <meta name="vs_defaultClientScript" content="JavaScript">
9 <meta name="vs_targetSchema" content="http://schemas.microsoft.com/intellisense/ie5">
10 <script type="text/javascript">
11 function votes()
12 {
13 for(var i=1;i<=4;i++)
14 {
15 var target = document.getElementById("cb_"+i);
16 if(target.checked)
17 {
18 vote_ajax.vote.GetVote(i,GetVote_callback);
19
20 return;
21
22 }
23 }
24
25
26 }
27
28 function GetVote_callback(response)
29 {
30 alert("感谢您的投票!");
31 }
32
33 </script>
34 </HEAD>
35 <body>
36 <form id="Form1" method="post" runat="server">
37 <TABLE id="Table1" style="WIDTH: 197px; HEIGHT: 218px" cellSpacing="0" cellPadding="0"
38 width="197" border="1">
39 <TR height="30">
40 <TD bgColor="#ff9966"></TD>
41 </TR>
42 <TR>
43 <TD style="HEIGHT: 38px"><INPUT id="cb_1" type="radio" name="vote"> <span id="a"><%=v.A%></span></TD>
44 </TR>
45 <TR>
46 <TD style="HEIGHT: 34px"><INPUT id="cb_2" type="radio" name="vote"> <span id="b"><%=v.B%></span></TD>
47 </TR>
48 <TR>
49 <TD style="HEIGHT: 33px"><INPUT id="cb_3" type="radio" name="vote"> <span id="c"><%=v.C%></span></TD>
50 </TR>
51 <TR>
52 <TD style="HEIGHT: 33px"><INPUT id="cb_4" type="radio" name="vote"> <span id="d"><%=v.D%></span></TD>
53 </TR>
54 <TR>
55 <TD vAlign="top" height="31">
56 <TABLE id="Table2" style="WIDTH: 192px; HEIGHT: 31px" cellSpacing="0" cellPadding="0" width="192"
57 border="0">
58 <TR>
59 <TD align="right" width="50%"><INPUT type="button" value="确定" id="vote" onclick="votes()"></TD>
60 <TD align="left" width="50%"><INPUT type="button" value="查看" id="cancel"></TD>
61 </TR>
62 </TABLE>
63 </TD>
64 </TR>
65 </TABLE>
66 <FONT face="宋体">
67 <BR>
68 </FONT>
69 <DIV id="div" style="WIDTH: 100px; HEIGHT: 100px" ms_positioning="FlowLayout"></DIV>
70 </form>
71 </body>
72</HTML>
73
cs:
1using System;
2using System.Collections;
3using System.ComponentModel;
4using System.Data;
5using System.Drawing;
6using System.Web;
7using System.Web.SessionState;
8using System.Web.UI;
9using System.Web.UI.WebControls;
10using System.Web.UI.HtmlControls;
11using System.Configuration;
12using System.Data.SqlClient;
13using AjaxPro;
14using vote_ajax;
15using System.Text;
16
17namespace vote_ajax
18{
19 /// <summary>
20 /// WebForm1 的摘要说明。
21 /// </summary>
22 public class vote : System.Web.UI.Page
23 {
24 public readonly string strcn = ConfigurationSettings.AppSettings["strcn"].ToString();
25 public vote_ajax.bs_vote v;
26 public string info;
27 public ArrayList list;
28 public string alpht = "ABCD";
29 public char[] got = new char[4];
30
31 private void Page_Load(object sender, System.EventArgs e)
32 {
33 AjaxPro.Utility.RegisterTypeForAjax(typeof(vote));
34 got = alpht.ToCharArray();
35 }
36
37 [AjaxPro.AjaxMethod]
38 public string GetVote(string num)
39 {
40 SqlConnection mycn = new SqlConnection(strcn);
41 SqlCommand mycm =new SqlCommand();
42 mycm.CommandType = CommandType.StoredProcedure;
43 mycm.Connection = mycn;
44 SqlParameter pram = new SqlParameter("@id",SqlDbType.VarChar,50);
45 mycm.CommandText = "pr_addVote";
46 pram.Value = num;
47 mycm.Parameters.Add(pram);
48
49 try
50 {
51 mycn.Open();
52 mycm.ExecuteNonQuery();
53 }
54 catch(SqlException ex)
55 {
56 info = ex.Message;
57
58 }
59 finally
60 {
61 mycn.Close();
62 }
63
64 return " ";
65 }
66
67
68
69
70 #region Web 窗体设计器生成的代码
71 override protected void OnInit(EventArgs e)
72 {
73 //
74 // CODEGEN: 该调用是 ASP.NET Web 窗体设计器所必需的。
75 //
76 InitializeComponent();
77 base.OnInit(e);
78 v = new bs_vote();
79 v.GetIt();
80 }
81
82 /// <summary>
83 /// 设计器支持所需的方法 - 不要使用代码编辑器修改
84 /// 此方法的内容。
85 /// </summary>
86 private void InitializeComponent()
87 {
88 this.Load += new System.EventHandler(this.Page_Load);
89
90 }
91 #endregion
92
93
94 }
95}
96