大家好,有一个问题想请教一下:
我在页面上放了很多个用户控件,在访问的时候我做了一个函数
Sub ShowCarLocation(ByVal pg As Web.UI.Page)
Dim C As Web.UI.Control
For Each C In pg.Controls
If TypeOf C Is Web.UI.UserControl Then
If CType(C, UCCar).Pid Is Nothing Then
C.Visible = False
Else
C.Visible = True
End If
End If
Next
End Sub其中Pid属性是用户控件的属性.
请问一下为什么总是不能判断不成功,明明我的页面上有用户控件,请指教!
我在页面上放了很多个用户控件,在访问的时候我做了一个函数
Sub ShowCarLocation(ByVal pg As Web.UI.Page)
Dim C As Web.UI.Control
For Each C In pg.Controls
If TypeOf C Is Web.UI.UserControl Then
If CType(C, UCCar).Pid Is Nothing Then
C.Visible = False
Else
C.Visible = True
End If
End If
Next
End Sub其中Pid属性是用户控件的属性.
请问一下为什么总是不能判断不成功,明明我的页面上有用户控件,请指教!
foreach(DataListItem anItem in DataList1.Items)
{
butSendCar1 = (Button)anItem.FindControl("butSendCar1");
}
能不能给出一些代码,指引一下呢
就是大控件里面套小控件,一次遍历没办法找到所有的。
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
'在此处放置初始化页的用户代码
Dim C As Web.UI.Control
For Each C In Page.Controls
Dim I As String = C.GetType.ToString
Next
End Sub
做了下调试,发现I的值分别是
System.Web.UI.ResourceBasedLiteralControl
System.Web.UI.HtmlControls.HtmlForm
System.Web.UI.LiteralControl
我只知道中间一个,其余不知道是什么类,如何遍历?
Dim C As Web.UI.Control
For Each C In control.Controls If(C.HasControls()) Then ShowCarLocation(C) If TypeOf C Is Web.UI.UserControl Then
If CType(C, UCCar).Pid Is Nothing Then
C.Visible = False
Else
C.Visible = True
End If
End If
Next
End Sub