页面上有一个DropDownList 控件 设置了 AutoPostback 为 True ,当选择了不同的Value值时,动态加载不同的用户控件
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
If Not IsNothing(drplstDepart.Items.FindByValue(strDepartID)) Then
drplstDepart.SelectedValue = strDepartID
DispReportTable(drplstDepart.SelectedValue, strRptID)
End If
End Sub
Private Sub DispReportTable(ByVal strValue As String, Optional ByVal strRptID As String = Nothing)
Dim typUser As Type
Dim propUserRetUrl As PropertyInfo
Dim ctrl As UserControl = Nothing
Select Case strValue
Case "2"
ctrl = LoadControl("*****/****.ascx")
Case "4"
ctrl = LoadControl("*****/****.ascx")
Case "7"
ctrl = LoadControl("*****/****.ascx")
Case "8"
ctrl = LoadControl("*****/****.ascx")
End Select
If IsNothing(ctrl) Then
Exit Sub
End If
ctrl.ID = UseExtControlName
typUser = ctrl.GetType()
'Set the ReturnURL value
propUserRetUrl = typUser.GetProperty("ReturnURL")
propUserRetUrl.SetValue(ctrl, "frm***.aspx", Nothing)
'typUser.InvokeMember("ClearAllTextBox", BindingFlags.InvokeMethod, Nothing,, Nothing)
plDepartMent.Controls.Clear()
'ADD the UserControl to Page
plDepartMent.Controls.Add(ctrl)
end sub
如果这几个用户控件很类似,为什么不做成一个用户控件然后用参数来控制界面和逻辑呢?
如果界面相差太多,也可以用mutiview这个控件来控制这个用户控件的view呀。
看vb的代码很累....