日期:2014-05-18  浏览次数:20422 次

点击日历控件出现 “未将对象引用设置到对象的实例。“
同一个页面有日历 还有投票功能,

点击日历的日期会使投票出错。


投票页面HTML源代码

C# code

<%@ Control Language="C#" AutoEventWireup="true" CodeFile="toupiao.ascx.cs" Inherits="XmlVote.toupiao" %>



<fieldset>
            <legend accesskey="F"  style="FONT-WEIGHT:bold;COLOR:#000000;font-size:12px" align=center>
                    <%=VoteTitle%></legend>
                    <ul style="list-style-type:none;margin-left:50px">
                    <%for(int i=0;i<xnl.Count;i++)
                    {
                     System.Xml.XmlNode xn = xnl.Item(i);%>
                    <li>
                    <input type=checkbox name="vote" value="<%=xn.SelectSingleNode("VoteID").InnerText%>" /><%=xn.SelectSingleNode("Title").InnerText%> 
                <%}%>
                </li>
                </ul>
                <div align=center><asp:Button id="Vote" runat="server" Text="投票" OnClick="Vote_Click"></asp:Button>&nbsp;&nbsp;<input 
                        type=button value="查看结果" 
                        onclick="javascript:var url='vote/ShowVote.aspx?i=0&voteid=<%=Request.QueryString["VoteID"]%>';window.open(url,'_blank','left=10,top=20,width=675,height=360');return false;" 
                        style="height: 26px" /></div>
            </fieldset>





投票页面CS源代码

C# code

using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Xml;




namespace XmlVote
{

    public partial class toupiao : System.Web.UI.UserControl
    {
        protected XmlNodeList xnl;
        protected string VoteTitle = "";
        protected System.Web.UI.WebControls.Button Button1;

        private XmlDocument myDoc = new XmlDocument();

        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
                BindXML("1");
        }
        private void BindXML(string VoteID)
        {

            myDoc.Load(Server.MapPath("vote/DB_hyy.xml"));

            XmlNode xn = myDoc.SelectSingleNode("//VoteInfo[ID='" + VoteID + "']");
            VoteTitle = xn.SelectSingleNode("VoteTitle").InnerText;
            xnl = xn.SelectNodes("Item");
        }

        protected void Vote_Click(object sender, EventArgs e)
        {
            string VoteID = "1";
            //通过Cookie记录投票
            if (Request.Cookies["IsVote"] != null)
            {
                Response.Write("<script>alert('对不起,你已投过票!');document.location=document.location;</script>");
            }
            else
            {

                if (Request.Form["Vote"] != null && Request.Form["Vote"] != "")
                {
                    string[] votes = Request.Form["Vote"].Split(',');
                    myDoc.Load(Server.MapPath("vote/DB_hyy.xml"));

                    XmlNode xn = myDoc.SelectSingleNode("//VoteInfo[ID='" + VoteID + "']");

                    for (int i = 0; i < votes.Length - 1;