i've been working on this for some time now but I can't seem to be able to find the answer... Google doesn't really help me today!
I'm working on an C# website that uses a lot of forms with a lot of validation on it. Big forms which have to be typed by hand, (no problems there though).
The problem that I have is that I always want my ValidationControls to have the Display Property set to dynamic.
I have found a work around but I'm not convinced that this is the best solution.
Currently I have a BaseValidatorControlAdapter that sets the validators display type to "Dynamic" like this:
public class BaseValidatorControlAdapter : ControlAdapter
{
protected override void Render(System.Web.UI.HtmlTextWriter writer)
{
System.Web.UI.WebControls.BaseValidator _control = (System.Web.UI.WebControls.BaseValidator)this.Control;
_control.Display = System.Web.UI.WebControls.ValidatorDisplay.Dynamic;
base.Render(writer);
}
}
This is then triggerd by adding an App_Browser which looks like this
<browsers>
<browser refID="Default">
<controlAdapters>
<adapter controlType="System.Web.UI.WebControls.BaseValidator"
adapterType="BaseValidatorControlAdapter" />
</controlAdapters>
</browser>
</browsers>
My question for you is. Is it possible for me to set the default value of Display for any validator control. Because my current solution just overrides what there is right now and there is no way of changing that. Therefor when the situation arrises that I do need something else then dynamic in the display option there is no solution for it.
I'm almost convinced that there is a better solution to this.
Any advice is appreciated!
Edit august 2nd 2012:
I finally settled with the solution to override the default asp.net controls and add the following constructor to them
public controlname ()
: base ()
{
this.Display = "Dynamic";
}
I added all these controls to a namespace and now I can do
<validator:RequiredField ID="RqrdFld_x" runat="server" Display="Static" />
Essentially overriding the default value in my control definition and overriding the default control Display value of Dynamic in the constructor.