开发者

Get a particular validator

I can get particular validator using

Page.Validators[0]

Can anyone tell me开发者_开发技巧 is there a way to get a specific validator searching using its ID?


You can search for any control on the page using FindControl. It returns a Control so you'll need to cast it to it's proper type:

var rfv = (RequiredFieldValidator)Page.FindControl("rfv");

If the control exists within a container you'll need to find it from that container's control collection rather than from the Page.


If you have a validator on your front-end, like:

<asp:SomeValidator ID="vField" ... runat="server" />

You can just access that validator in your code-behind like:

protected void Page_Load(object sender, EventArgs e)
{
    vField.Property = "value";
}
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜