Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Setting properties of a custom control

Status
Not open for further replies.

Algernon83

Programmer
Jun 25, 2004
50
US
I've made a custom web control, but I find that when I use it, the properties of it are not set as I expect, and I get a null reference exception when opening the page. What is the correct format for setting object properties of a web control? More detail follows, if necessary:

The control is for security purposes. Specifically, it is meant to check whether the user currently logged in is a member of one of a set of groups, showing different content depending on the answer. The control class (CheckPoint) has two members, Success and Failure, each of which is a ControlCollection that defines the content to show in case of success (user in appropriate group) or failure. I currently have it on the page in the following format:

<Security:CheckPoint runat="server">
<Groups>
<asp:ArrayList>
<asp:Int16>1</asp:Int16>
</asp:ArrayList>
</Groups>
<Success>
Hello, world!
</Success>
<Failure>
Goodbye, world!
</Failure>
</Security:CheckPoint>

Groups is a bit clunky; I'll probably change it to a delimited list eventually. At any rate, even if I reduce the CheckPoint class's Render method to:

foreach (Control c in this.Success)
{
c.RenderControl(output)
}

I receive a null reference error. Do non-scalar properties of controls need to be set programatically, e.g. in the page_load event?
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top