ASP:在用户控件文字控制空 [英] asp:Literal control null in user control

查看:125
本文介绍了ASP:在用户控件文字控制空的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经包含ASP用户控件:文字。

I've a user control which contains asp:Literal.

<div>
     <asp:Literal id="MenuContainer" runat="server" />
</div>

有在$ C $的方法C-隐藏页它初始化控制:

There is a method in code-behind page which initializes the control:

internal void Setup(MyBusinessObject obj)
{
    MenuObject menu = MenuHelper.GetMenu(obj.State);

    if(obj == null)
        MenuContainer.Visible = false;

    //other code
}

在控制使用我调用页面的设置控制方法的 LoadComplete 事件处理程序(我第一次调用它的加载的事件)。不管的 MyBusinessObject 的为空或不为空,当我访问的文字的用户控制,我得到错误:

In the page where the control is used I call Setup method of control in LoadComplete event handler (I was first calling it in Load event). Irrespective of MyBusinessObject being null or not null, when I access Literal on user-control I get error:

Object reference not set to an instance of an object.

原因是什么,什么是补救呢?

What is the reason and what is the remedy for this?

推荐答案

这是非常简单的。我将在web.config中的控件部分事情,有人建议由里克Sthral 在他的文章中的一个(:(用于GOT有关的帖子,你将不得不寻找他页)。

It was very simple. I was adding things in web.config's controls section as was suggested by Rick Sthral in one of his post ( :( for got about the post, you will have to search on his page).

这是很好的让我添加控件没有把 @注册标签,但缺点是对我的控件的子控件被显示为空!所以我干脆把 @注册指令在我的网页和它的工作。

It was nicely allowing me to add controls without putting @ Register tag but the downside was that child controls on my controls were shown as null! so I simply put @ Register directive in my pages and it worked.

这篇关于ASP:在用户控件文字控制空的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆