Last post Mar 29, 2005 12:00 PM by firstname.lastname@example.org
Mar 26, 2005 09:18 PMemail@example.com|LINK
I have created my own custom textbox by inherting from the System.Web.UI.Webcontrols.Textbox.
I basically wanted to add two new propertys. These properties pass in a couple of strings and I use that to do some processing. Depending on the results I may want to set visible and enabled to false.
I first tried just setting the Me.Visible or Me.Enabled, or MyBase.Visible to false prior to the render and that did not work.
I was able to get it to work by creating a new instance of a textbox, setting all of the properties manually (I did use the CopyBaseAttributes method) and then setting visible and enabled to false and then render that control in my override render method.
I am worried that it will cause me problems with processing.
There must be a better way to do this. I am not changing the appearance of this control only whether it is visible or enabled. (I am doing some role based checking).
Thanks any help is appreciated.
Mar 27, 2005 06:34 AM|joteke|LINK
Mar 27, 2005 04:14 PMfirstname.lastname@example.org|LINK
Here is the code. I have even tried hard coding visible to false just before the render.
_Key = Value
_AuthorizedViewRoles = GetViewRolesFromKey(
_AuthorizedViewRoles = Value
_roleList = Value
[Text] = "[" + [Text] + "]"
[Text] = tmpText
Mar 28, 2005 02:29 AM|joteke|LINK
problem is simple, along these lines:
Sub Render(ByVal output
The bolded line. Yes, indeed you can't set Visible property in Render method, reason being that Visible property determines whether Render is method is called at all.
It needs to be set before Render, literally.
It works so that when Control is asked to render itself, RenderControl method is called. RenderControl determines based on Visible property value if Render method will be called. So the check doesn't happen in base class's Render method but
in RenderControl, which makes the Visible set in your overriden Render method to not to have any impact.
Answer is that set this property in OnPreRender.
Mar 28, 2005 12:30 PM|PLBlum|LINK
You should attempt to set all properties in OnPreRender.
Visible is a very special property. It turns on and off the ability for ASP.NET to call both OnPreRender and Render events. Its not so bad to set it to false in OnPreRender so long as you consider these issues:
Mar 29, 2005 12:00 PMemail@example.com|LINK