Board index » Web Programming » Either ValidationProperty or ValidationPropertyAttribute do not wo

Either ValidationProperty or ValidationPropertyAttribute do not wo

Web Programming207
I am applying the ValidationProperty property to a modified custom control

that I am using:



[

ValidationProperty("Text")

]

public class ComboBox : System.Web.UI.WebControls.ListControl,

IPostBackDataHandler, INamingContainer

{





According to the Microsoft docs, this should be sufficient to expose the

Text property for required and other types of validation.



My required validator renders correctly, but no client side validation occurs:



<mbcbb:combobox id="cbStates" CssClass="ComboBox" runat="server"

TextCssClass="TextBox" ButtonCssClass="ButtonSystem"></mbcbb:combobox>

<asp:requiredfieldvalidator id="vreqStates" CssClass="errors" runat="server"

Display="Dynamic" ControlToValidate="cbStates">*</asp:requiredfieldvalidator>



I also tried ValidationPropertyAttribute instead of ValidationProperty, but

it did not work.



Is there any method in my custom control that I need to watch closely when

overriding? Please advise, thanks.


-
 

Re:Either ValidationProperty or ValidationPropertyAttribute do not wo

setting this property only tell the serverside validation routines how to

deal with your control, it gives no info to the clientside validation

routines. if you want clientside validation, create a custom validator that

knows how to validate your control on both client and serverside.



-- bruce (sqlwork.com)



"Yuri Vanzine" <YuriVanzine@discussions.microsoft.com>wrote in message

| I am applying the ValidationProperty property to a modified custom control

| that I am using:

|

| [

| ValidationProperty("Text")

| ]

| public class ComboBox : System.Web.UI.WebControls.ListControl,

| IPostBackDataHandler, INamingContainer

| {

|

|

| According to the Microsoft docs, this should be sufficient to expose the

| Text property for required and other types of validation.

|

| My required validator renders correctly, but no client side validation

occurs:

|

| <mbcbb:combobox id="cbStates" CssClass="ComboBox" runat="server"

| TextCssClass="TextBox" ButtonCssClass="ButtonSystem"></mbcbb:combobox>

| <asp:requiredfieldvalidator id="vreqStates" CssClass="errors"

runat="server"

| Display="Dynamic"

ControlToValidate="cbStates">*</asp:requiredfieldvalidator>

|

| I also tried ValidationPropertyAttribute instead of ValidationProperty,

but

| it did not work.

|

| Is there any method in my custom control that I need to watch closely when

| overriding? Please advise, thanks.

|

|

|

|





-

Re:Either ValidationProperty or ValidationPropertyAttribute do not wo

Well I got the answer in the original asp.net validation in depth article by

microsoft:



http://msdn.microsoft.com/library/default.asp?url" rel="nofollow" target="_blank">msdn.microsoft.com/library/default.asp=/library/en-us/dnaspp/html/aspplusvalid.asp



"For validation to work client-side as well, this property must correspond

to the value attribute of the HTML element that gets rendered on the client.

Many complex controls such as DataGrid and Calendar do not have a value on

the client and can only be validated on the server. This is why only controls

that correspond closely to HTML elements can be involved in validation. Also,

a control must have a single logical value on the client. This is why

RadioButtonList can be validated, but CheckBoxList cannot."



My control is composite so for client side to work I have to reference the

Textbox subcomponent directly by using the textbox's UniqueID:





<mbcbb:combobox id="cbStates" CssClass="ComboBox" runat="server"

TextCssClass="TextBox" ButtonCssClass="ButtonSystem"></mbcbb:combobox>



<asp:requiredfieldvalidator id="vreqStates" CssClass="errors" runat="server"

Display="Dynamic"

ControlToValidate="cbStates:Text">*</asp:requiredfieldvalidator>



Notice the controlToValidate property. It is a hack but this is what I could

come up with so far. If you know a better method, please let me know. Thanks.









"Yuri Vanzine" wrote:



Quote
I am applying the ValidationProperty property to a modified custom control

that I am using:



[

ValidationProperty("Text")

]

public class ComboBox : System.Web.UI.WebControls.ListControl,

IPostBackDataHandler, INamingContainer

{





According to the Microsoft docs, this should be sufficient to expose the

Text property for required and other types of validation.



My required validator renders correctly, but no client side validation occurs:



<mbcbb:combobox id="cbStates" CssClass="ComboBox" runat="server"

TextCssClass="TextBox" ButtonCssClass="ButtonSystem"></mbcbb:combobox>

<asp:requiredfieldvalidator id="vreqStates" CssClass="errors" runat="server"

Display="Dynamic" ControlToValidate="cbStates">*</asp:requiredfieldvalidator>



I also tried ValidationPropertyAttribute instead of ValidationProperty, but

it did not work.



Is there any method in my custom control that I need to watch closely when

overriding? Please advise, thanks.









-