I found another thread with a similar problem here: Visual studio 2010: Can't show design view but in my case I'm not using a custom control.
On a Win7 32 bit machine I am using Visual Studion 2010 to create an asp.net web applications using Visual Basic code. I have added standard web controls to the default.aspx form.
Yesterday I saved the project, ran it in debug mode for a bit, then closed Visual Studio (no changes made since last save).
Today when I open the solution and look at the Design view of the default.aspx file, all the controls that should display instead say "Error creating control - control-name. Object reference not set to an instance of an object"
I made no changes to the solution.
No errors are displayed in the error List. The web app builds without error. The app runs without error (in debug mode) and displays the controls correctly on the web page.
I had a suggestion that the default.aspx.designer.vb file might be out of date. The suggestion was to delete the file, create an empty file of the same name, open the solution, and resave the default.aspx file to regenerate the designer file. I did that, and it had no impact.
I have not installed any updates on my system.
Other VS solutions for web apps that I used as a basis for this one still open fine. They don't show this problem in their design views.
All code is stored locally on the same machine as Visual Studio. Version control is not in use.
This is actually the second time this problem has happened to me with this project. It happened two days ago. At that time I started a new solution file, recreated the default.aspx (and code-behinds) from scratch, and then copied over my other code (class, module, and text files). That is the solution file I'm working with now, and as I mentioned, it was working fine yesterday. In both cases, I coincidentally had the same set of controls on the form when I closed the project for the day. I have not tried to add anothe control to the form.
This has got something to do with the OnInit
method.
one workaround for this issue can be to check if we are in the design mode after the base.OnInit()
call.
protected override void OnInit( EventArgs e)
{
base.OnInit(e);
if(!this.DesignMode)
{
// place code here for dynamic control creation
TextBox txtUserName = new TextBox();
txtUserName.ID= "UserID" ;
usersPlaceholder.Controls.Add(txtUserName);
}
}
The visual web developer team is also aware of this issue and they say:
this is a bug in VS 2010 that we’re now calling the OnInit() method at the
design time; we are considering a fix for this in a future release of
VisualStudio.
Check the complete details for this issue on their blogs here
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With