Last post Jul 19, 2009 03:14 AM by XIII
Jul 19, 2009 01:59 AM|vishnusharma|LINK
I have created a custom control that derives from WebControl class. I have defined a property called "ItemCount" in the custom control.
This custom control is created as a separate project and the assembly is added to the main web project (VS 2005 Web Site).
Just to test, I have only one line writer.Write("Hello World!")
in the overriden "RenderContents" method in the web control.
Once added to the aspx file, the control renders the text perfectly fine and is declared in the aspx file as
<cc:mycontrol ID="_testControl" runat="server"/>
Now, when I try to access the control "_testControl" in the codebehind, I cannot compile and I get the error as "The name '_testControl' does not exist in current context.
After reading multiple posts, I tried declaring the control in my aspx codebehind as
protected MYControl _testControl;
This comes out to be NULL during run-time. I'm not too familiar with asp.net, but if other controls (e.g. Button, Textbox) are accessible in my codebehind including their properties, should the same logic be not applied to WebControls...they are all the
I can create a new instance of the _testControl in the OnInit method, but that defeats the whole purpose. I need to understand what is going on and what is the right way to solve it.
Thanks in advance...
web control properties codebehind
Jul 19, 2009 03:14 AM|XIII|LINK
can you provide the source code of the control and the test page?
Did you also provide the name in codebehind (which event are you placing it?) with the namespace of your assembly included?