views:

90

answers:

6

I know the title is vague, sorry I couldn't think of a better way to title it:

I have had this happen several times before; when I copy code from a asp .net page and paste it into another page none of the controls are recognized in the code behind page. I have tried to build/rebuild the page but I can't see the controls (in intellesense) and the build fails. Also any controls I drag/drop from the toolbox won't be seen after I copy the code...

I assume that it has something to do with those autogenerated designer files that say not to mess with them, but there should be a way "teach" the project about the controls without having to make them from scratch; I mean I never use code snippets for controls, but what if I did???

Thanks for any advice on this. I'm using VS 2008 Professional BTW.

+1  A: 

If you are trying to copy markup (the aspx, not the aspx.cs) then you could try switching to the design view and cutting and pasting that. This way it will update the mysterious designer file (you can mess with this, give it a try and see what happens). :)

Mark Dickinson
It finally worked!But what worked for me was copy/pasting from design mode, not switching to design mode after it was already pasted.I'm glad I'm not the only one who has had this issue.Thanks again!
wali
A: 

There's a setting to turn off autogenerate control IDs under options. Thats what you're looking for...

NickAtuShip
Now that i reread the question, I see what you mean. If you switch to design mode and click on an element, it generally will regenerate the designer file
NickAtuShip
A: 

Make sure you set CodeBehind and Inherits elements of the Page tag <%@ Page .... %> to the code behind (.cs) file.

madatanic
A: 

I've noticed this sometimes happening. Try switching from markup to design mode after you paste.

Greg
Thanks, but it only worked if I copied from design mode to design mode. Thanks again!
wali
A: 

Unless the markup you copy in is invalid, Visual Studio should automatically update the .designer.cs file. If it does not, right clicking the project and choosing "Convert to Web Application" (yes, it is available even for web applications) might do the trick. Not a very clean/explainable solution, but it has worked for me a few times, though.

Jørn Schou-Rode
A: 

Of course, when you paste html code into another page, control IDs will change (unless you have that turned off in options). That's obvious thing to check.

If you rule out naming problems then it might be issue with VS. For some mysterious reason sometimes VS will not update designer file after you paste into aspx. I came across this frustrating problem as well. What you need to do is to regenerate designer file:

Go delete designer file then right click aspx file and select "Convert to Web Application". That should do it.

Maciej