Iterate though all controls on asp.net page

前端 未结 3 1799
误落风尘
误落风尘 2021-01-15 05:14

I\'m using ascx and I need to iterate through all of the controls and selects each that have cssClass attribute set to \'required\'.

I have the following code:

3条回答
  •  情话喂你
    2021-01-15 05:49

    Regarding your comment on the answer above, you need to first check that it is a WebControl and then cast it to a WebControl

    var webControl = childControl as WebControl;
    
    if(webControl != null)
    {
       if(webControl.CssClass == 'required')
       // Do your stuff
    }
    

提交回复
热议问题