找了半天也没找到问题在哪,以前运行正常,最近出这个js缺少对象问题了,我使用vs2008,IE8,win7,只是最近从vista升级到win7了,或者是2010年的问题?呵呵,我实在没办法了,大家帮忙,源代码如下:(js文件直接复制在页面文件中没有错误,但是包含js文件使用就缺少对象)
页面文件:<%@ Page Language="C#" MasterPageFile="~/MasterPage1.master" AutoEventWireup="true" CodeFile="SaleReportAll.aspx.cs" Inherits="SaleReport" Title="Untitled Page" %>
 <asp:Content ID="Content1" ContentPlaceHolderID="ContentPlaceHolder1" Runat="Server">
   <script language="javascript" src="PopupCalendar.js" ></script>
    <table width="650" align="center"><tr><td height="30" valign="bottom" align=center>
    销售报表</td></tr><tr><td align="center" style="border:double">
        &nbsp;日期:<asp:TextBox ID="TextBox1" runat="server" Width="80px"   onClick="ShowCalendar(this.id)"></asp:TextBox>
        <asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server" ControlToValidate="TextBox1"
            Display="Dynamic" ErrorMessage="*"></asp:RequiredFieldValidator>
        <asp:RegularExpressionValidator id="RegularExpressionValidator2" ControlToValidate="TextBox1" runat="server" Display="Dynamic"  ErrorMessage="格式错误" ValidationExpression="^(\d{2}|\d{4})[\-\/]((0?[1-9])|(1[0-2]))[\-\/]((0?[1-9])|((1|2)[0-9])|30|31)$"></asp:RegularExpressionValidator>&nbsp;至&nbsp;
        <asp:TextBox ID="TextBox2" runat="server" Width="80px"   onClick="ShowCalendar(this.id)"></asp:TextBox>
        <asp:RequiredFieldValidator ID="RequiredFieldValidator2" runat="server" ControlToValidate="TextBox2"
            Display="Dynamic" ErrorMessage="*"></asp:RequiredFieldValidator>
        <asp:RegularExpressionValidator Display="Dynamic" id="RegularExpressionValidator1" ControlToValidate="TextBox2" runat="server" ErrorMessage="格式错误" ValidationExpression="^(\d{2}|\d{4})[\-\/]((0?[1-9])|(1[0-2]))[\-\/]((0?[1-9])|((1|2)[0-9])|30|31)$"></asp:RegularExpressionValidator>
       格式:2006-01-01</td></tr>
       <tr><td align=center>
        <asp:Button ID="Button1" runat="server" Text="查询" OnClick="Button1_Click" />
          
    </td>
    </tr>
     <tr>
    <td align=center>
        <asp:Label ID="Label1" runat="server" Text=""></asp:Label> &nbsp; <asp:ImageButton ID="ImageButton2" runat="server" ImageUrl="~/images/excel.gif" OnClick="ImageButton2_Click" ToolTip="导出到excel" />&nbsp;<asp:ImageButton ID="ImageButton1" runat="server" ImageUrl="~/images/word.gif" OnClick="ImageButton1_Click" ToolTip="导出到word" /></td>
    </tr>
    <tr>
    <td align=center>
 <asp:GridView ID="GridView1" runat="server" DataSourceID="SqlDataSource2" SkinID="dv" 
            AutoGenerateColumns="False" Width="650px" 
            OnRowDataBound="GridView1_RowDataBound" ShowFooter="True" 
            FooterStyle-Font-Bold="true" FooterStyle-ForeColor="red" AllowSorting="True">
     <Columns>
     <asp:BoundField DataField="ProStyle" HeaderText="产品型号" SortExpression="ProStyle" />
     <asp:TemplateField HeaderText="产品名称">
     <ItemTemplate>
         <asp:Label ID="Label2" runat="server" Text=""></asp:Label></ItemTemplate>
     </asp:TemplateField>
     <asp:BoundField DataField="Color" HeaderText="颜色" SortExpression="Color" />
     <asp:BoundField DataField="销售数量" HeaderText="销售数量" SortExpression="销售数量" />
         <asp:BoundField DataField="销售金额" HeaderText="销售金额" SortExpression="销售金额" />
         <asp:BoundField DataField="赊账数量" HeaderText="赊账数量" SortExpression="赊账数量" />
         <asp:BoundField DataField="赊账金额" HeaderText="赊账金额" SortExpression="赊账金额" />
     </Columns>
     <FooterStyle Font-Bold="True" ForeColor="Red" />
        </asp:GridView>
        <asp:SqlDataSource ID="SqlDataSource2" runat="server" ConnectionString="<%$ ConnectionStrings:MISConnectionString %>"
            
            
            SelectCommand="SELECT ProStyle, Color, 
销售数量=sum(case when Arrearage='否' then Number else 0 end),
    销售金额=sum(case when Arrearage='否' then Number*Price else 0 end),
    赊账数量=sum(case when Arrearage='是' then Number else 0 end),
    赊账金额=sum(case when Arrearage='是' then Number*Price else 0 end)
 FROM (SELECT id, ProStyle, Color, Type, Number, SaleId, ProName, Price, Unit,Arrearage FROM net_sale_detail WHERE (SaleId IN (SELECT SaleId FROM net_sale WHERE (SaleDate BETWEEN @start AND DATEADD(d, 1, @end))))) as t1 GROUP BY Color, ProStyle">
            <SelectParameters>
                <asp:ControlParameter ControlID="TextBox1" Name="start" PropertyName="Text" Type="DateTime" />
                <asp:ControlParameter ControlID="TextBox2" Name="end" PropertyName="Text" />
            </SelectParameters>
        </asp:SqlDataSource>
    </td>
    </tr></table>
          
</asp:Content>

解决方案 »

  1.   


    js文件(PopupCalendar.js):
    [code=JScript]
    // 日期选择
    // By Ziyue(http://www.web-v.com/)
    var months = new Array("一月", "二月", "三月", "四月", "五月", "六月", "七月", "八月", "九月", "十月", "十一月", "十二月"); 
    var daysInMonth = new Array(31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31); 
    var days = new Array("日","一", "二", "三", "四", "五", "六"); 
    var today; document.writeln("<div id='Calendar' style='position:absolute; z-index:1; visibility: hidden; filter:\"progid:DXImageTransform.Microsoft.Shadow(direction=135,color=#999999,strength=3)\"'></div>");function getDays(month, year)

        //下面的这段代码是判断当前是否是闰年的 
        if (1 == month) 
            return ((0 == year % 4) && (0 != (year % 100))) || (0 == year % 400) ? 29 : 28; 
        else 
            return daysInMonth[month]; 
    } function getToday() 

        //得到今天的年,月,日 
        this.now = new Date(); 
        this.year = this.now.getFullYear(); 
        this.month = this.now.getMonth(); 
        this.day = this.now.getDate(); 
    }function getStringDay(str) 

        //得到输入框的年,月,日
        var str=str.split("-")
        
        this.now = new Date(parseFloat(str[0]),parseFloat(str[1])-1,parseFloat(str[2])); 
        this.year = this.now.getFullYear(); 
        this.month = this.now.getMonth(); 
        this.day = this.now.getDate(); 
    }function newCalendar() { 
        var parseYear = parseInt(document.all.Year.options[document.all.Year.selectedIndex].value); 
        var newCal = new Date(parseYear, document.all.Month.selectedIndex, 1); 
        var day = -1; 
        var startDay = newCal.getDay(); 
        var daily = 0; 
        
        if ((today.year == newCal.getFullYear()) &&(today.month == newCal.getMonth())) 
            day = today.day; 
            
        var tableCal = document.all.calendar; 
        var intDaysInMonth =getDays(newCal.getMonth(), newCal.getFullYear());
         
        for (var intWeek = 1; intWeek < tableCal.rows.length;intWeek++) 
            for (var intDay = 0;intDay < tableCal.rows[intWeek].cells.length;intDay++) 
            { 
                var cell = tableCal.rows[intWeek].cells[intDay]; 
                if ((intDay == startDay) && (0 == daily)) 
                    daily = 1; 
                    
                if(day==daily) //今天,调用今天的Class 
                {
                    cell.style.background='#6699CC';
                    cell.style.color='#FFFFFF';
                    //cell.style.fontWeight='bold';
                }
                else if(intDay==6) //周六 
                    cell.style.color='green'; 
                else if (intDay==0) //周日 
                    cell.style.color='red';
                
                if ((daily > 0) && (daily <= intDaysInMonth)) 
                { 
                    cell.innerText = daily; 
                    daily++; 
                } 
                else 
                    cell.innerText = ""; 
            } 
    } function GetDate(InputBox)

        var sDate; 
        //这段代码处理鼠标点击的情况 
        if (event.srcElement.tagName == "TD") 
            if (event.srcElement.innerText != "") 
            { 
                sDate = document.all.Year.value + "-" + document.all.Month.value + "-" + event.srcElement.innerText;
                eval("document.all."+InputBox).value=sDate;
                HiddenCalendar();
            } 
    } function HiddenCalendar()
    {
        //关闭选择窗口
        document.all.Calendar.style.visibility='hidden';
    }function ShowCalendar(InputBox)
    {
        var x,y,intLoop,intWeeks,intDays;
        var DivContent;
        var year,month,day;
        var o=eval("document.all."+InputBox);
        var thisyear; //真正的今年年份
        
        thisyear=new getToday();
        thisyear=thisyear.year;
        
        today = o.value;
        if(isDate(today))
            today = new getStringDay(today);
        else
            today = new getToday(); 
        
        //显示的位置
        x=o.offsetLeft;
        y=o.offsetTop;
        while(o=o.offsetParent)
        {
            x+=o.offsetLeft;
            y+=o.offsetTop;
        }
        document.all.Calendar.style.left=x+2;
        document.all.Calendar.style.top=y+20;
        document.all.Calendar.style.visibility="visible";
        
        //下面开始输出日历表格(border-color:#9DBAF7)
        DivContent="<table border='0' cellspacing='0' style='border:1px solid #0066FF; background-color:#EDF2FC'>";
        DivContent+="<tr>";
        DivContent+="<td style='border-bottom:1px solid #0066FF; background-color:#C7D8FA'>";
        
        //年
        DivContent+="<select name='Year' id='Year' onChange='newCalendar()' style='font-family:Verdana; font-size:12px'>";
        for (intLoop = thisyear - 35; intLoop < (thisyear + 2); intLoop++) 
            DivContent+="<option value= " + intLoop + " " + (today.year == intLoop ? "Selected" : "") + ">" + intLoop + "</option>"; 
        DivContent+="</select>";
        
        //月
        DivContent+="<select name='Month' id='Month' onChange='newCalendar()' style='font-family:Verdana; font-size:12px'>";
        for (intLoop = 0; intLoop < months.length; intLoop++) 
            DivContent+="<option value= " + (intLoop + 1) + " " + (today.month == intLoop ? "Selected" : "") + ">" + months[intLoop] + "</option>"; 
        DivContent+="</select>";
        
        DivContent+="</td>";
        
        DivContent+="<td style='border-bottom:1px solid #0066FF; background-color:#C7D8FA; font-weight:bold; font-family:Wingdings 2,Wingdings,Webdings; font-size:16px; padding-top:2px; color:#4477FF; cursor:hand' align='center' title='关闭' onClick='javascript:HiddenCalendar()'>S</td>";
        DivContent+="</tr>";
         
        DivContent+="<tr><td align='center' colspan='2'>";
        DivContent+="<table id='calendar' border='0' width='100%'>";
        
        //星期
        DivContent+="<tr>";
        for (intLoop = 0; intLoop < days.length; intLoop++) 
            DivContent+="<td align='center' style='font-size:12px'>" + days[intLoop] + "</td>"; 
        DivContent+="</tr>";
        
        //天
        for (intWeeks = 0; intWeeks < 6; intWeeks++)
        { 
            DivContent+="<tr>"; 
            for (intDays = 0; intDays < days.length; intDays++) 
                DivContent+="<td onClick='GetDate(\"" + InputBox + "\")' style='cursor:hand; border-right:1px solid #BBBBBB; border-bottom:1px solid #BBBBBB; color:#215DC6; font-family:Verdana; font-size:12px' align='center'></td>"; 
            DivContent+="</tr>"; 
        } 
        DivContent+="</table></td></tr></table>";    document.all.Calendar.innerHTML=DivContent;
        newCalendar();
    }function isDate(dateStr)

        var datePat = /^(\d{4})(\-)(\d{1,2})(\-)(\d{1,2})$/;
        var matchArray = dateStr.match(datePat);
        if (matchArray == null) return false; 
        var month = matchArray[3];
        var day = matchArray[5]; 
        var year = matchArray[1]; 
        if (month < 1 || month > 12) return false; 
        if (day < 1 || day > 31) return false; 
        if ((month==4 || month==6 || month==9 || month==11) && day==31) return false; 
        if (month == 2)
        {
            var isleap = (year % 4 == 0 && (year % 100 != 0 || year % 400 == 0)); 
            if (day > 29 || (day==29 && !isleap)) return false; 
        } 
        return true;
    }[/code]
      

  2.   

    报错,是报错在这行:
    &nbsp;日期:<asp:TextBox ID="TextBox1" runat="server" Width="80px"   onClick="ShowCalendar(this.id)"></asp:TextBox>就是找不到ShowCalendar,编码问题已经不可能了,也不是路径问题
      

  3.   

    <script language="javascript" src="PopupCalendar.js" ></script>
    js文件路径正确吗?确定下。
    如果没问题,可能是js文件编码问题。用notepad打开,另存为,选择编码,几种都试一下
      

  4.   

    OnClientClick用这个事件如果是用了母版页的话这个引入js放在marst页面好了!
      

  5.   

    CSDN社区技术交流群开放了,欢迎大家踊跃加入,探讨技术,交流经验。 CSDN社区技术交流群号(超级群,可容纳500人):73769287
      

  6.   

    试试:就是把 <script></script> 放到ContentPlaceHolderID="head" 的里面(id要与母版页对应)
    然后使用 type="text/javascript",再者就是src路径<asp:Content ID="Content0" ContentPlaceHolderID="head" runat="server">
        <script type="text/javascript" src="<%=Request.ApplicationPath == "/" ? "" :Request.ApplicationPath %>/PopupCalendar.js"></script>
    </asp:Content>
    http://www.mybuffet.net
      

  7.   

    自己搞定了居然把PopupCalendar.js文件名改成JScript.js就正常了,彻底无语!改成其他文件名都可以,就是不能改成以Popup为开头的文件名,为啥?难道此文件名是保留的?
      

  8.   

    PopupCalendar可能和某个对象冲突
      

  9.   

    真的很奇怪,另外新建一个新项目,引用的js文件名就是不能以Popup开头,大家试试看
      

  10.   

    看看是不是杀毒软件挡住了所有文件名含有Popup的js文件?禁用所有杀毒软件
      

  11.   

    换其他电脑以Popup开头试试
    应该与系统有关
      

  12.   


    因为你在MasterPage中,正确的编程方法是给出js文件准确的路径。例如:<script type="text/javascript" src='<%=  this.ResolveUrl("~/Scripts/file1.js") %>' />
      

  13.   

    晕了,真的是杀毒软件的问题,卡巴斯基把带有popup文件名的js都屏蔽了,谢谢18楼的,也谢谢其他各位。
      

  14.   

    如果不是win32系统下运行正常的话,可能就是IIS配置问题,64位下,有时运行不了32位的程序。遇到同样问题,各种错 
    1 webform_autoFocus("")  缺少对象
    2 不能加载Microsoft Ajax客户端框架解决方案 应用程序池,高级设置,启用32位应用程序 设为 TRUE。
    一切OK了。郁闷同事也默认安装,我的不知怎么就设为FALSE了,害我抓狂了两天!!