环通过对Web用户控件控件 [英] Loop Through Controls on Web User Control

查看:69
本文介绍了环通过对Web用户控件控件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有通过都在我的用户控制的控制循环的问题。

I'm having problems looping through controls that are on my user control.

我曾尝试以下code,但不能让它来查找用户控件上的复选框。 (你可以看到一些我注释掉我的previous尝试。)

I have tried the following code, but cannot get it to find the checkboxes that are on the user control. (You can see some of my previous attempts that I have commented out.)

    'For Each Ctrl As Control In Page.Controls
    'For Each Ctrl As Control In Me.Page.Controls
    'For Each ctrl As Control In Request.Form
     '''Dim frm As Control = Me.FindControl("frmDefault")
     '''For Each Ctrl As Control In frm.Controls

    Dim Check As CheckBox

    For Each Ctrl As Control In Me.Controls
        If TypeOf Ctrl Is CheckBox Then
            Check = Ctrl
            ' Do something here...
        End If
    Next

有用户控件的多个chekcboxes。上面显示的code是在页面背后的code用户控件。

There are multiple chekcboxes on the user control. The code shown above is on the code behind page for the user control.

(用户控件在我的CMS,Sitecore的结合使用。我不知道这对我经历或没有问题的任何影响。)

(The user control is being used in conjunction with my CMS, Sitecore. I'm not sure if this has any effect on the problem I am experiencing or not.)

有什么建议?

推荐答案

我终于想通了是怎么回事。

I finally figured out what is going on.

我有不同的表内的复选框。这些表中包含的 =服务器的。此表是div标签还包含一个的 =服务器的内部。

I have the checkboxes inside different tables. These tables contains runat="server". This table is inside a Div tag that also contains a runat="server".

我的code再也找不到因为这个复选框。我不得不添加的对于每个的通过div标签循环,并找到合适的桌。然后我就通过表圈,以便找到的复选框。

My code could never find the checkboxes because of this. I had to add a For Each that loops through the Div tag and find the appropriate table(s). I then had to loop through the tables in order to find the checkboxes.

这篇关于环通过对Web用户控件控件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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