使用 init 方法后母版设计时视图被破坏
我正在使用 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技术交流群](/public/img/jiaqun_03.jpg)
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
尝试将所有数据绑定放入以下内容中。 (对 C# 代码感到抱歉)。我认为它是VB中的
Me.DesignMode
。填充下拉菜单();
隐藏问题Div();
隐藏下拉菜单();
我不确定这是否适用于嵌套用户控件,但值得一试。请注意,这在构造函数内不起作用,只能在其他事件中起作用。
MSDN 此处。
Try putting all your databinding inside the following. (sorry about the c# code). I think it is
Me.DesignMode
in VB.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.