RequiredFieldValidator.RenderControl [英] RequiredFieldValidator.RenderControl

查看:66
本文介绍了RequiredFieldValidator.RenderControl的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,

我今天开发了一个页面,该页面构建了一系列RadioButtonList,这些字段可能是必填字段,也可能不是必填字段.

I have today developed a page that builds a series of RadioButtonLists, which may or may not be required fields.

由于页面根据数据库值的不同而不同,因此我已使用.RenderControl()呈现了控件.

As the page varies depending on DB values, I have rendered the controls using .RenderControl().

不幸的是,我现在没有要提交的代码,但是它包含以下内容:

Unfortunatley I do not have the code to hand right now, but its along the lines of:

RadioButtonList rblQuestion =新的RadioButtonList();
rblQuestion.id = question.ID;
//添加ListItems ...

RequiredFieldValidator rfvQuestion = new RequiredFieldValidator();
rfvQuestion.ControlToValidate = rblQuestion.ID;
rfvQuestion.ErrorMessage ="*";

RadioButtonList rblQuestion = new RadioButtonList();
rblQuestion.id = question.ID;
// Add ListItems...

RequiredFieldValidator rfvQuestion = new RequiredFieldValidator();
rfvQuestion.ControlToValidate = rblQuestion.ID;
rfvQuestion.ErrorMessage = "*";

然后我在rblQuestion和rfvQuestion上都使用.RenderControl,连接成一个字符串,然后使用HTML字符串填充PlaceHolder.

I then use .RenderControl on both rblQuestion and rfvQuestion, concatenate into a string then use the HTML String to populate a PlaceHolder.

这似乎很好用,除了RequiredFieldValidator之外,所有内容均按预期方式显示-每个RadioButtonList旁边都有一个红色星号(My ErrorMessage)-但这会在页面加载后立即出现,而不是在单击帖子/按钮时出现.

This seems to work fine, all appears as expected apart from the RequiredFieldValidator - I get a red asterix (My ErrorMessage) next to each RadioButtonList - But this appears as soon as the page loads, not on a post/button click.

任何帮助将不胜感激-我已经对此进行了研究,到目前为止没有任何进展.

Any help would be much appreciated - I've researched this and not got anywhere thus far.

谢谢! ; o)

Simon.

推荐答案

将代码包装在

如果不是Page.IsPostback

If Not Page.IsPostback

亚当


这篇关于RequiredFieldValidator.RenderControl的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆