User Control Problem

  • Thread starter Thread starter CJF
  • Start date Start date
C

CJF

I have a user control that I created with a dddlb and a public subroutine to
load the ddlb based on a value passed. I put the user control on my form
(id=ucDepartmentList1) and created a variable in my page's code-behind by
the same name "ucDepartmentList1" protected with events. When I go to call
the subroutine in my user control from my page code-behind I keep getting an
error that I have a null object reference and ucDepartmentList1 is set to
nothing. I double-checked the name of the variable to the user control id
and they do match and they both are instances of the same class
(ucDepartmentList). What could be happening? I've attached code below.
Thanks

UserControl Class:
Public Class ucDepartmentList

Inherits System.Web.UI.UserControl

#Region ...

...

Protected WithEvents ddlbDepartments As
System.Web.UI.WebControls.DropDownList

...

InitializeComponent()

End Sub

#End Region

Private objDataTable As DataTable

ReadOnly Property CurrentValue() As String

Get

Return ddlbDepartments.SelectedValue

End Get

End Property

Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load

...


End Sub

Public Sub LoadList(ByVal strCollege As String)

'Get DataSet with static data

objDataTable = DirectCast(Cache("OFFC"), DataTable)

If objDataTable Is Nothing Then

...

End If

Dim objDataView As New DataView

...

ddlbDepartments.DataSource = objDataView

ddlbDepartments.DataValueField = "office_cd"

ddlbDepartments.DataTextField = "office_longname"

ddlbDepartments.DataBind()

End Sub

End Class

----------------------------------------------------------------------------
----------------------------------------------------------------------------
----------------------

Page Code-Behind

Public Class ClassSearch

Inherits System.Web.UI.Page

Protected WithEvents ucCollegeList1 As ucCollegeList

Protected WithEvents ucDepartmentList1 As ucDepartmentList

Protected WithEvents ucToolbar1 As toolBar

Protected objDataView As New DataView

....

Private Sub ucCollegeList1_Changed(ByVal sender As Object, ByVal e As
ucCollegeList.CollegeSelectionChangedEventArgs) _

Handles ucCollegeList1.CollegeSelectionChanged

'Load Departments

ucDepartmentList1.LoadList(e.Value) '*** .NET errors out here saying
ucDepartmentList1 is set to nothing, control id and variable name match

End Sub
 
You know, I think VS.NET has some bug issues. I completely deleted the user
control and all referneces to it from the page and started over and it all
works fine now.
 
Back
Top