locked
Designer Generated Code RRS feed

  • Question

  • User-1585762441 posted

    Hi.

     In .net 3.5, the code generated by the designer present in .net 1.1 has disappeared. How can I access that code?

    Monday, March 17, 2008 10:41 AM

Answers

  • User1340541308 posted

    I don't believe VS will let you do this. Even if you did change something VS would undoubtedly overwrite it next time it re-generated the designer code. That is the whole point of the partial classes is that they can generate and regenerate code ad nauseum without worrying about the code you've written because it is in a seperate file. Any change you want to make to what was set up in the designer should be done in your code file (setting control properties, etc.) not in the generated code.

    Typically if the compiler doesn't recognize controls that are on the designer this is because the inherits attribute on you page directive does not match the name of your class in the code file.
     

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Monday, March 17, 2008 12:37 PM

All replies

  • User1340541308 posted

    Starting with .Net 2 they introduced the concept of partial classes. Basically it means you can split a class definition across 2 files. They used this functionality to isolate the designer generated code that you used to see in your source files into a separate source file and then you enter your code in your code file. At compile time the 2 files that make up the class are effectively combined to form a single class definition.

    This is a nice thing because it keeps that generated code out of your code file and prevents accidents (like accidentally deleting/modifying generated) code from happening. It also means that as you make changes in the designer the designer can regenerate the code in the one source file without affecting the code in your file.

     
    Under normal circumstances I can't think of any reason why you should ever want or need to access that generated code. Why do you need access to it?
     

    Monday, March 17, 2008 11:26 AM
  • User-1585762441 posted

    I need it because I come from a .net 1.1 background and I do like to be able to make changes that way when I need to. Also, I am converting an app from 2.0 to 3.5, and I am having an issue where the compiler doesn't recognise some controls which are on the designer, so I want to make sure they are being created in the code designer...

    Monday, March 17, 2008 11:36 AM
  • User1340541308 posted

    I don't believe VS will let you do this. Even if you did change something VS would undoubtedly overwrite it next time it re-generated the designer code. That is the whole point of the partial classes is that they can generate and regenerate code ad nauseum without worrying about the code you've written because it is in a seperate file. Any change you want to make to what was set up in the designer should be done in your code file (setting control properties, etc.) not in the generated code.

    Typically if the compiler doesn't recognize controls that are on the designer this is because the inherits attribute on you page directive does not match the name of your class in the code file.
     

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Monday, March 17, 2008 12:37 PM
  • User-1585762441 posted

    Thank you very much. I have found out like you said that the page declaration was eronous.

     Thanks for your help, I unserstand better the concept....

    Monday, March 17, 2008 12:42 PM