Solved

ASP.net Error adding control in Page PreInit event

Posted on 2016-10-21
3
42 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 63

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 63

Expert Comment

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

Featured Post

Space-Age Communications Transitions to DevOps

ViaSat, a global provider of satellite and wireless communications, securely connects businesses, governments, and organizations to the Internet. Learn how ViaSat’s Network Solutions Engineer, drove the transition from a traditional network support to a DevOps-centric model.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Help with preventing selection from a combobox 11 34
Could not load file or assembly 'Microsoft.Web.Infrastructure 4 33
JSON Deserialize issue 6 26
asp.net mvc 2 20
A quick way to get a menu to work on our website, is using the Menu control and assign it to a web.sitemap using SiteMapDataSource. Example of web.sitemap file: (CODE) Sample code to add to the page menu: (CODE) Running the application, we wi…
Problem Hi all,    While many today have fast Internet connection, there are many still who do not, or are connecting through devices with a slower connect, so light web pages and fast load times are still popular.    If your ASP.NET page …
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…

808 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