O
oerz
Hey y'all,
I'm stuck. I know it will turn out it's not the system's fault, but at
the moment I do not have a clue.
What I am doing is very simple. I have a dropdownlist which is
populated by a function. That works fine. But if I try to access that
same dropdownlist AFTER the function was called, I am getting an
"Object reference not set to an instance of an object"-error.
Please look at the following code:
testDdl.aspx
============
<%@ Page Language="VB" Inherits="TestDdl" Src="testDdl.aspx.vb"
Debug="true" %>
<html>
<body>
<form id="testform" runat="server">
<asp:dropdownlist class="text_form" id="ddlTest"
runat="server"/>
<asp:Label class="text_label" id="lblInfo"
runat="server"/>
</form>
</body>
</html>
testDdl.aspx.vb
===============
Imports System.Web.UI
Imports System.Web.UI.WebControls
Imports System.Collections
Public Class TestDdl
Inherits Page
public lblInfo as label
public ddlTest as dropDownList
sub Page_Load
'*** this works fine ***
lblInfo.Text = ddlTest.UniqueID
'*** this works, too ***
ddlTest = fillDdlTest(ddlTest)
'*** same as above, produces error ***
lblInfo.Text &= ddlTest.UniqueID
'*** also this produces an error ***
setTest()
end sub
public sub setTest()
'*** same line as the last of fillDdlTest, but won't work ***
ddlTest.Items.FindByText("Test 1").Selected=true
end sub
public function fillDdlTest(ByRef dropDown as dropdownlist)
dim arrTest As New ArrayList
arrTest.Add(" ")
arrTest.Add("Test 1")
arrTest.Add("Test 2")
arrTest.Add("Test 3")
arrTest.TrimToSize()
dropDown.DataSource=arrTest
dropDown.DataBind()
dropDown.Items.FindByText("Test 2").Selected=true
end function
End Class
Of course would I find a work-around, but this is just a simplified
example of a more complex application.
Does anyone have the answer for me?
I'm stuck. I know it will turn out it's not the system's fault, but at
the moment I do not have a clue.
What I am doing is very simple. I have a dropdownlist which is
populated by a function. That works fine. But if I try to access that
same dropdownlist AFTER the function was called, I am getting an
"Object reference not set to an instance of an object"-error.
Please look at the following code:
testDdl.aspx
============
<%@ Page Language="VB" Inherits="TestDdl" Src="testDdl.aspx.vb"
Debug="true" %>
<html>
<body>
<form id="testform" runat="server">
<asp:dropdownlist class="text_form" id="ddlTest"
runat="server"/>
<asp:Label class="text_label" id="lblInfo"
runat="server"/>
</form>
</body>
</html>
testDdl.aspx.vb
===============
Imports System.Web.UI
Imports System.Web.UI.WebControls
Imports System.Collections
Public Class TestDdl
Inherits Page
public lblInfo as label
public ddlTest as dropDownList
sub Page_Load
'*** this works fine ***
lblInfo.Text = ddlTest.UniqueID
'*** this works, too ***
ddlTest = fillDdlTest(ddlTest)
'*** same as above, produces error ***
lblInfo.Text &= ddlTest.UniqueID
'*** also this produces an error ***
setTest()
end sub
public sub setTest()
'*** same line as the last of fillDdlTest, but won't work ***
ddlTest.Items.FindByText("Test 1").Selected=true
end sub
public function fillDdlTest(ByRef dropDown as dropdownlist)
dim arrTest As New ArrayList
arrTest.Add(" ")
arrTest.Add("Test 1")
arrTest.Add("Test 2")
arrTest.Add("Test 3")
arrTest.TrimToSize()
dropDown.DataSource=arrTest
dropDown.DataBind()
dropDown.Items.FindByText("Test 2").Selected=true
end function
End Class
Of course would I find a work-around, but this is just a simplified
example of a more complex application.
Does anyone have the answer for me?