سؤال

I have written a custom ASP.NET Server Control. When I am rendering the control, I check the this.Enabled property to determine if I should add the disabled attribute to my tag (extract of code below). Unless I specifically set the Enabled flag, this value is True regardless of the state of the panel it is in.

output.AddAttribute(HtmlTextWriterAttribute.Type, "text");
if (!this.Enabled)
{
    output.AddAttribute(HtmlTextWriterAttribute.Disabled, "disabled");
}
output.AddAttribute(HtmlTextWriterAttribute.Value, this.DisplayName);
output.RenderBeginTag(HtmlTextWriterTag.Input);
output.RenderEndTag();

Standard server controls like textboxes etc, behave as expected in this scenario and are disabled.

What is the pattern that I must implement to be able to check if the control is actually to be disabled or not? Do you have to check the parent(s) to see if any of them are a Panel and then see if they are enabled? Seems very inefficient if that were the case.

Thanks Mark

هل كانت مفيدة؟

المحلول

Just found it.

Needed to modify the code to:

output.AddAttribute(HtmlTextWriterAttribute.Type, "text");
if (!this.IsEnabled)
{
    output.AddAttribute(HtmlTextWriterAttribute.Disabled, "disabled");
}
output.AddAttribute(HtmlTextWriterAttribute.Value, this.DisplayName);
output.RenderBeginTag(HtmlTextWriterTag.Input);
output.RenderEndTag();
مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top