Search code examples
c#asp.netdefault-valueweb-controls

Setting The Default Value Of ASP.NET Controls


Suppose we have <asp:RequiredFieldValidator ... /> and we want to the default value of Display to be Dynamic. I couldn't think of any better way to set it than

span[style="visibility:hidden;"],span[style="visibility: hidden;"] {
    display:none;
}

and I didn't find anything (simple) in Google. What do you recommend?


Solution

  • Create a theme with a skin for asp:RequiredFieldValidator and set its Display property to Dynamic. Then each page you set to have that theme will default its validators to Display = "Dynamic".

    Note that if you set the SkinID on the validator in the skin template, then you will also have to set the SkinID on all asp:RequiredFieldValidors you use throughout your page(s). If you really want every validator to default to dynamic, don't set a SkinID.