Solved

ASP.net Error adding control in Page PreInit event

Posted on 2016-10-21
3
23 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
Comment Utility
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
Comment Utility
Great answer. Thanks very much
0
 
LVL 62

Expert Comment

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

Featured Post

6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

Join & Write a Comment

This document covers how to connect to SQL Server and browse its contents.  It is meant for those new to Visual Studio and/or working with Microsoft SQL Server.  It is not a guide to building SQL Server database connections in your code.  This is mo…
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…
This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're looking for how to monitor bandwidth using netflow or packet s…

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

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now