Problem With User Controls Dim Statement

C

crjunk

I have a user control on my web form. When I Try to declare a
varialbe that references a dropdown list on my user control, I receive
an error. Is their something wrong with my decloration statement?


Dim UControlNew As UserControl = Page.FindControl("ReceivedRecord1")
' Web forms bombs out on the ddlFYYearNew Dim statement.
Dim ddlFYYearNew As DropDownList =
UControlNew.FindControl("ddlFYYear")

Thanks!

Crjunk
 
K

Ken Cox [Microsoft MVP]

Are you sure you are getting a reference to the ddl?

Try separating out the statements like this:

Dim ddlFYYearNew As DropDownList
ddlFYYearNew =UControlNew.FindControl("ddlFYYear")
if isnothing(ddlFYYearNew) then
response.write("Didn't get a reference!")
end if

This should help you determine where the problem is acting showing up.

Ken
 
C

crjunk

I tried your suggestion, but this did not work. I finally figured out
what my problem was. Originally the code looked like this:

Public Class RecordScreen
Inherits System.Web.UI.Page
Dim UControlNew As UserControl =
Page.FindControl("ReceivedRecord1")
' Web forms bombs out on the ddlFYYearNew Dim statement.
Dim ddlFYYearNew As DropDownList =
UControlNew.FindControl("ddlFYYear")

After placing both Dim statements inside my OnClick event, the problem
went away. I assumed that I could declare my variables as show above.

Thanks for your help!
crjunk
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,139
Messages
2,570,805
Members
47,352
Latest member
DianeKulik

Latest Threads

Top