首页 文章

非静态方法或字段错误需要一个对象

提问于
浏览
1
Type cstype = this.GetType();


        ClientScriptManager cs = Page.ClientScript;  ///Broken line


        if (!cs.IsStartupScriptRegistered(cstype, "loadvideo"))
        {
            StringBuilder cstext3 = new StringBuilder();
            cstext3.Append("jwplayer(\"vidplayer\").setup({");
            cstext3.Append("flashplayer:\"./players/player.swf\",");
            cstext3.Append("file: \"");
            cstext3.Append("./video.mp4");
            cstext3.Append("\",height: 270,");
            cstext3.Append("width: 400");
            cstext3.Append("});");
            cs.RegisterStartupScript(cstype, "loadvideo", cstext3.ToString(), true);

“非静态字段,方法或属性'System.Web.UI.Page.ClientScript.get'”需要对象引用

指定行中的错误 . 我该怎么办?

2 回答

  • 2

    假设此代码来自页面本身,请尝试使用此代码...

    ClientScriptManager cs = this.ClientScript;  ///Broken line
    
  • 2

    Page.ClientScript 不是静态属性,因此您不能以这种方式使用它 . 假设您有 Page 实例,名为 pageInstance ,可以在方法中访问,请使用以下代码:

    ClientScriptManager cs = pageInstance.ClientScript;
    

相关问题