Solved

ASP.net Error adding control in Page PreInit event

Posted on 2016-10-21
3
40 Views
Last Modified: 2016-10-21
Hi. The following code gives me an error at the line marked "Error Here"

    Private Sub Dynamic_Data_PreInit(sender As Object, e As EventArgs) Handles Me.PreInit
        Dim oDropDownList As New DropDownList
        oDropDownList.ID = "d1"
        oDropDownList.Items.Add("Test")
        Me.Panel_Controls.Controls.Add(oDropDownList) 'Error here
  End Sub

1
0
Comment
Question by:murbro
  • 2
3 Comments
 
LVL 62

Accepted Solution

by:
Fernando Soto earned 500 total points
ID: 41853796
I am not a web developer but from the exception the control that has issues is the Panel_Controls. From Microsoft documentation during Page.PreInit the controls have not yet been initialized and therefore the error. Try using the Page.Init event, this is where the controls have already been initialized.
0
 

Author Closing Comment

by:murbro
ID: 41853809
Great answer. Thanks very much
0
 
LVL 62

Expert Comment

by:Fernando Soto
ID: 41853826
Not a problem murbro, glad I was able to help.
0

Featured Post

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

A long time ago (May 2011), I have written an article showing you how to create a DLL using Visual Studio 2005 to be hosted in SQL Server 2005. That was valid at that time and it is still valid if you are still using these versions. You can still re…
This article shows how to deploy dynamic backgrounds to computers depending on the aspect ratio of display
This Micro Tutorial hows how you can integrate  Mac OSX to a Windows Active Directory Domain. Apple has made it easy to allow users to bind their macs to a windows domain with relative ease. The following video show how to bind OSX Mavericks to …
This video shows how to use Hyena, from SystemTools Software, to bulk import 100 user accounts from an external text file. View in 1080p for best video quality.

772 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question