当前位置: 代码迷 >> ASP.NET >> 点击日历控件出现 “未将对象引用设置到对象的实例。“解决思路
  详细解决方案

点击日历控件出现 “未将对象引用设置到对象的实例。“解决思路

热度:6263   发布时间:2013-02-25 00:00:00.0
点击日历控件出现 “未将对象引用设置到对象的实例。“
同一个页面有日历 还有投票功能,

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


投票页面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; i++)                    {                        XmlNode xn0 = xn.SelectSingleNode("Item[VoteID='" + votes[i] + "']");                        xn0.SelectSingleNode("Count").InnerText = Convert.ToString(Convert.ToInt32(xn0.SelectSingleNode("Count").InnerText) + 1);                    }                    myDoc.Save(Server.MapPath("vote/DB_hyy.xml"));                }                Response.Cookies["IsVote"].Value = "true";                Response.Cookies["IsVote"].Expires.AddHours(1);                Response.Write("<script>window.open('vote/ShowVote.aspx?i=0&voteid=" + VoteID + "','_blank','left=10,top=20,width=675,height=360');document.location='?voteid=" + VoteID + "';</script>");            }            Response.End();        }    }}
  相关解决方案