使用 init 方法后母版设计时视图被破坏

发布于 2024-11-27 13:45:15 字数 401 浏览 4 评论 0原文

我正在使用 asp.net 4、.net 4 和母版页。我将以下代码添加到我的子页面

    Private Sub FoodChain_Init(ByVal sender As Object, ByVal e As EventArgs) Handles Me.Init

    MyBase.OnInit(e)

    PopulateDropdowns()
    HideQuestionDiv()
    HideDropdowns()

End Sub

并运行我的应用程序。该应用程序运行良好,但当我返回设计视图时,我现在收到一条错误消息“对象引用未设置到实例”。这仅在设计时视图和引用主占位符期间有效。

这是一个错误还是我错过了什么?正如我所说,应用程序运行良好,但现在在运行时出现问题。

I am using asp.net 4, .net 4 and masterpages. I added in the following code to my child page

    Private Sub FoodChain_Init(ByVal sender As Object, ByVal e As EventArgs) Handles Me.Init

    MyBase.OnInit(e)

    PopulateDropdowns()
    HideQuestionDiv()
    HideDropdowns()

End Sub

and ran my app. The app runs fine but when I went back to the design view I now get an error saying "object reference not set to an instance". This is only during design time view and referencing the main place holder.

Is this a bug or am I missing something ? As I said the application runs fine and there are now issues during runtime.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

抹茶夏天i‖ 2024-12-04 13:45:15

尝试将所有数据绑定放入以下内容中。 (对 C# 代码感到抱歉)。我认为它是VB中的Me.DesignMode

if (!this.DesignMode)
{

填充下拉菜单();
隐藏问题Div();
隐藏下拉菜单();

}

我不确定这是否适用于嵌套用户控件,但值得一试。请注意,这在构造函数内不起作用,只能在其他事件中起作用。

MSDN 此处

Try putting all your databinding inside the following. (sorry about the c# code). I think it is Me.DesignMode in VB.

if (!this.DesignMode)
{

PopulateDropdowns();
HideQuestionDiv();
HideDropdowns();

}

I'm not sure if this works correctly for nested user controls but worth a try. Note that this won't work inside a constructor, only other events.

MSDN here.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文