【问题标题】:An object is required for the non-static method or field error非静态方法或字段错误需要对象
【发布时间】:2015-08-12 07:40:09
【问题描述】:
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'"

指定行中的错误。我该如何解决?

【问题讨论】:

标签: c# jwplayer


【解决方案1】:

Page.ClientScript 不是静态属性,所以不能这样使用。假设您有一个名为 pageInstancePage 实例,可以在方法中访问,请改用以下代码:

ClientScriptManager cs = pageInstance.ClientScript;

【讨论】:

  • 感谢您的回答,但我现在收到此错误。 “当前上下文中不存在名称‘pageInstance’”
  • 'pageInstance' 应替换为您的 Page 实例的变量名称。
  • 谢谢。现在没有错误。我有个问题。我如何把它放在表格中。我想以这种形式运行 jwplayer。
【解决方案2】:

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

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2012-05-03
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多