开发者

Adding attributes to validator programmatically

I'm building a function to allow me to add validators into dynamically created tables. They work, in that they show up on the page and function properly. But I'm trying to add the "Display" attribute via the codebehind, and any combination of parameters fails...

                RequiredFieldValidator newRQValid = new RequiredFieldValidator();
                newRQValid.SetFocusOnError = true;
                newRQValid.ControlToValidate = txtID;
                newRQValid.Display = "dynamic";  <<---  
                strID = "cv" + cel开发者_JAVA百科lID;
                newRQValid.ID = strID;
                newRQValid.ErrorMessage = txtErrorMessage;
                newRQValid.InitialValue = initval;
                tCell.Controls.Add(newRQValid);

I've tried with and without quotes, but "Dynamic" doesn't even appear in the autocomplete, so I'm assuming I'm just plain mistaken.

I have similar issues adding attributes to a compare validator as well:

                CompareValidator newCMValid = new CompareValidator();
                newCMValid.SetFocusOnError = true;
                newCMValid.ControlToValidate = cellID;
                newCMValid.ControlToCompare = "txt_clm_dob";
                newCMValid.Type = ValidationDataType(DateTime);   <<==
                newRGValid.Display = Dynamic;    <<==
                strID = "cv" + cellID;
                newCMValid.ID = strID;
                newCMValid.ErrorMessage = txtErrorMessage;
                newCMValid.Operator = LessThanEqual;  <<==
                tCell.Controls.Add(newCMValid);

With several attempts on each of those as well.

So what's the right syntax there, or is adding those attributes somehow not allowed here?


 newRQValid.Display = ValidatorDisplay.Dynamic;
 newCMValid.Type = ValidationDataType.Date;
 newCMValid.Operator = ValidationCompareOperator.LessThanEqual;
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜