如何在页面中获取所有requiredfieldvalidator并更改其errormessage?
我尝试使用下面的代码,但它会更改所有验证程序,包括regularexpressionvalidator。
library(ggplot2)
g <- function(mua=1.2){
mu0=0
g1<-ggplot(data.frame(x=c(-4.5, 4.5)),
aes(x)
) +
stat_function(fun=dnorm,args = list(mean=mu0), size = 1) +
stat_function(fun=dnorm,args = list(mean=mua), size = 1) +
geom_area(stat = "function", fun = dnorm,args=list(mean=mua), fill = "red",
xlim = c(qnorm(1-0.025,mean = mu0), 5),
alpha = 0.4) +
annotate(geom = "text",x=mu0,y=0,label="mu0") +
annotate(geom = "text",x=mua,y=0,label="mua") +
annotate(geom = "text",x=qnorm(1-0.025,mean = mu0),
y=0,label=round(qnorm(1-0.025,mean = mu0),2))
g1
}
plots1 <- vector("list", 6)
index=1
for(i in seq(0,2.5,by=0.5)){
plots1[[index]]=g(i)
index=index+1
}
plots1[[6]]=ggplot()
library(grid)
grobs1 = lapply(plots1, ggplotGrob)
row1 = do.call(cbind, c(grobs1[1:3], size="first"))
row2 = do.call(cbind, c(grobs1[4:6], size="first"))
grid1 = do.call(rbind,c(list(row1,row2), size="first"))
grid.newpage()
grid.draw(grid1)
答案 0 :(得分:0)
使用如下代码,其中验证器集合是通过Page对象的Page.Validators
属性获得的。此外,您需要使用下面的代码段中的if语句检查循环验证器是否为RequiredFieldValidator
。
foreach (IValidator validator in Page.Validators)
{
BaseValidator bv = (validator as BaseValidator);
//check if validator is a RequiredFieldValidator
if(bv is RequiredFieldValidator) {
bv.CssClass = "Error";
bv.Display = ValidatorDisplay.Dynamic;
bv.Text = "* Error Message!";
}
}
如果您使用Page.GetValidators(null)
,那么它仅为默认验证组提供验证器,即所有未指定验证组的验证器。这将排除已分配验证组的验证器。