【问题标题】:How to Access ASP.NET Page Controls During PreInit?如何在 PreInit 期间访问 ASP.NET 页面控件?
【发布时间】:2013-04-09 02:11:33
【问题描述】:

最近我使用here 解释的类在PreInit 期间访问动态控件。该帖子的标题为“在 PreInit 期间访问 ASP.NET 页面控件”,在本地它运行良好,但在服务器上我收到以下错误:

Compiler Error Message: CS1031: Type expected

Source Error:

Line 12:     /// in turn makes our controls accessible so that we can make the calls below. 
Line 13:     /// </remarks> 
Line 14:     public static void PrepareChildControlsDuringPreInit(this Page page)
Line 15:     {
Line 16:         // Walk up the master page chain and tickle the getter on each one 

如果有人就这个问题给我解决方案或建议,我将不胜感激。

【问题讨论】:

    标签: c# asp.net dynamic controls preinit


    【解决方案1】:

    听起来,您在本地运行的是比服务器更新的 .NET Framework 版本。

    我相信,扩展方法仅在 .NET 3.5 及更高版本中受支持(使用您正在使用的语法)。因此,如果您运行的 .NET Framework 版本低于服务器上的版本,我认为这会导致您遇到编译器错误(当它尝试在服务器上编译时)。

    【讨论】:

    • 嗨 :) 感谢您的回答。版本是一样的。还有其他解决办法吗?
    • 两者都是 3.5,虽然服务器也支持 4.5。
    • 我从 中删除了 "targetFramework="4.5" 并在本地得到了同样的错误。我该怎么办?
    • 我在 web.config 中找到了这些 4.0:
    • @Kardo 所以你的目标是本地站点上的 4.5。你在服务器上的目标是什么?
    猜你喜欢
    • 1970-01-01
    • 2018-07-15
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-11-09
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多