为什么我内嵌进入的js文件,它老是报错,一定要有对象才可以了,就是说我的javasceipt函数缺少对象,为什么呢?

解决方案 »

  1.   

    using System;
    using System.ComponentModel;
    using System.Security.Permissions;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using System.Web.UI;
    using System.Web.UI.WebControls;
    using System.Web.UI.HtmlControls;
    using System.Web;namespace WebCalendar
    {
        public class WebCalendar:WebControl,INamingContainer
        {        protected Button button = new Button();       // protected HtmlInputText text = new HtmlInputText();
            [
           Bindable(true),
           Category("Appearance"),
           DefaultValue(""),
           Description("The text to display on the button.")
           ]
            public string Text {
                get {
                    return button.Text;
                }
                set {
                    button.Text = value;
                }
            
            }        protected override void OnPreRender(EventArgs e) {
                if (!Page.ClientScript.IsClientScriptIncludeRegistered("WebCalendar")) {
                    Page.ClientScript.RegisterClientScriptInclude("WebCalendar",Page.ClientScript.GetWebResourceUrl(this.GetType(),"WebCalendar.WebCalendar.js"));
                    base.OnPreRender(e);
                
                }        }
            protected override void RenderContents(HtmlTextWriter writer)
            {
                //writer.AddAttribute("onclick","WebCalendar.yu()");
                this.button.Text = "选择日期";
                this.button.Height = 20;
                this.button.Width = 80;
                
                
                this.button.OnClientClick = "te.t()";
                
                //this.textbox.Text = "这里是日期";
                
                this.button.RenderControl(writer);
             //   this.text.RenderControl(writer);
                
                base.RenderContents(writer);
            }
        }
    }
    这是我的WebCalendar.cs文件
    [assembly: WebResource("WebCalendar.WebCalendar.js","text/javascript")]
    这是assembly的添加内容
    var te={t: function(){alert("cast down");}
    }
    这是WebCalendar.js文件
      

  2.   

    嗯,我连续发了两篇差不多的帖子,因为前一篇我解决了但是没有真的明白解决的错误原因是什么,经过这次以后,我发现,错误原因是多种多样的,包括js没有设置属性为内嵌的资源,或者你的这个js文件本身就有语法错误,但这是VS没有检测出来的。所以才会这样子。谢谢各位,虽然不是很有人队这个问题感兴趣。