Solved

ASP.net Error adding control in Page PreInit event

Posted on 2016-10-21
3
61 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:Murray Brown
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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:Murray Brown
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

PeopleSoft Has Never Been Easier

PeopleSoft Adoption Made Smooth & Simple!

On-The-Job Training Is made Intuitive & Easy With WalkMe's On-Screen Guidance Tool.  Claim Your Free WalkMe Account Now

Question has a verified solution.

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

Just a quick little trick I learned recently.  Now that I'm using jQuery with abandon in my asp.net applications, I have grown tired of the following syntax:      (CODE) I suppose it just offends my sense of decency to put inline VBScript on a…
Wouldn’t it be nice if you could test whether an element is contained in an array by using a Contains method just like the one available on List objects? Wouldn’t it be good if you could write code like this? (CODE) In .NET 3.5, this is possible…
Michael from AdRem Software outlines event notifications and Automatic Corrective Actions in network monitoring. Automatic Corrective Actions are scripts, which can automatically run upon discovery of a certain undesirable condition in your network.…
This tutorial will teach you the special effect of super speed similar to the fictional character Wally West aka "The Flash" After Shake : http://www.videocopilot.net/presets/after_shake/ All lightning effects with instructions : http://www.mediaf…

622 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