CustomControl.Page is undefined ?!?!?!

R

Robert Koritnik

I ran into a strange problem. I created my own server control that inherits
Control and INamingContainer. I override CreateChildControls() method.

Within this method i try to register some client script block with methods,
that the control container (the Page) provides (RegisterClientScriptBlock
etc.) When I try to check for slient script registration on the page i get
the "Object reference not set to an instance of an object." runtime error.
Debugging the code I realised that Custom control's property Page (inherited
by Control class) is null. Anybody knows why and when does that happen?

Robert
 
E

Eidolon

I think from your post, you are inheriting from the wrong class.

It is not Control that you want to inherit from but rather:

System.Data.Web.UI.WebControls.WebControl

The "Web"Control is where the Page property comes from.

HTH.
 
R

Robert Koritnik

What you are saying would be ridiculus because Repeater for instance
inherits from Control... Page comes from Control and not WebControl. And I
don't need the WebControl functionality, that's why I inherit from Control.

Check the Page property here:
http://msdn.microsoft.com/library/d.../html/frlrfsystemwebuicontrolmemberstopic.asp

Anyway. I figured it out. Before OnInit the Page property is not yet set so
if you are accessing it within any get/set property block you have to check
for its undefined value...
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,534
Members
45,008
Latest member
Rahul737

Latest Threads

Top