名称“序列化器”当前上下文中不存在 Java Script C# Web App 中的母版页错误
我已经使用java脚本在我的项目中成功运行,但是当我必须为此目的使用母版页和内容页时,我创建母版页并复制母版页的head标签中的所有css和脚本以及正文中的其余控件标签 然后我复制了 asp:content1 标签中的所有 css 和脚本,而另一个 asp:content2 标签中的所有其他内容显然删除了所有表单标签 当我编译内容页面时,它
在源文件 master 中给出错误“当前上下文中不存在‘序列化器’”
实际上,我使用此代码,其中实际上给出了错误,
我使用此命名空间“使用 System.Web.Script.Serialization ;” 然后在代码隐藏文件中使用此代码,
protected double[] Pvar;
protected JavaScriptSerializer serializer = new
System.Web.Script.Serialization.JavaScriptSerializer();
Pvar[runs] = Convert.ToDouble(output.Tables[0].Rows[runs][2]);
然后为了在客户端 javascript 中访问此数组,我使用此代码,
var Arr=<%= serializer.Serialize(Pvar)%>;
它在这一行中给出错误,但请记住代码是正确的,因为它在同一时间侧的简单 ASPX 页面上工作通过使用母版页和内容页..
希望您的建议,
i have use java script successfully running in my project but when i have to use master page and content page for this purpose i create master page and copy all css and script in the head tag of the master page and rest of the controls in the body tag
then i did copy all css and script in the asp:content1 tag while all other thing in the another asp:content2 tag abviously removed all form tags
when i compile content page it gave error
"'serializer' does not exist in the current context " in the source file master
actually i use this code in which is actually giving error,
i use this namespace "using System.Web.Script.Serialization;"
then use this code in the code behind file,
protected double[] Pvar;
protected JavaScriptSerializer serializer = new
System.Web.Script.Serialization.JavaScriptSerializer();
Pvar[runs] = Convert.ToDouble(output.Tables[0].Rows[runs][2]);
then for accessing this this array in client side javascript i use this code,
var Arr=<%= serializer.Serialize(Pvar)%>;
it giving error in this line but remember code is correct because it is working on a simple ASPX page on the same time side by using master page and content page ..
Hopes for your suggestions,
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您从哪个页面访问
serializer
对象?您无法从母版页标记中的内容代码隐藏访问受保护的变量,反之亦然。因此,请确保情况并非如此,否则您需要创建公共属性/方法,并通过在内容页中转换 Master 属性(或母版页中的 Page 属性)来访问它们,以更正类背后的代码。From which page, are you accessing the
serializer
object? You cannot access protected variable from content code-behind in master page markup and vice versa. So make sure that's not being the case otherwise you need to create public properties/methods and access them by casting Master property in content page (or Page property in Master page) to correct code behind class.