非静态方法或字段错误需要一个对象
An object is required for the non-static method or field error
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);
有
"An object reference is required for the non-static field, method, or
property 'System.Web.UI.Page.ClientScript.get'"
指定行出错。我该如何解决?
假设此代码来自页面本身,请试试这个...
ClientScriptManager cs = this.ClientScript; ///Broken line
Page.ClientScript
不是静态的 属性,所以你不能这样使用它。假设您有一个名为 pageInstance
的 Page
实例,可以在方法中访问它,请改用下面的方法:
ClientScriptManager cs = pageInstance.ClientScript;
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);
有
"An object reference is required for the non-static field, method, or property 'System.Web.UI.Page.ClientScript.get'"
指定行出错。我该如何解决?
假设此代码来自页面本身,请试试这个...
ClientScriptManager cs = this.ClientScript; ///Broken line
Page.ClientScript
不是静态的 属性,所以你不能这样使用它。假设您有一个名为 pageInstance
的 Page
实例,可以在方法中访问它,请改用下面的方法:
ClientScriptManager cs = pageInstance.ClientScript;