Last post Jun 25, 2007 06:03 AM by naturehermit
Jun 23, 2007 12:34 PM|mvidelgauz|LINK
Some time ago I used Studio 2003 to buid a web site and I used
Web Form Designer to add the following elements to my page: connection, adapter, label, button, etc. When I dragged those elements into design view of my page Studio 2003 automatically created the following code in the corresponding .VB file:
Protected WithEvents DataSetRecords
Also, Studio generated all initialisation and event handling code in .VB file, like the following:
Now I am trying to start building another site, but this time I am using Studio 2005. Again I created database connection and some visual elements in design page, but no code was generated in the corresponding .CS file (this time I am going
to use C# instead of .VB).
How can see all those objects created by visual designer? I want to access them to change some properties programmatically, to add events handles, to bind them with some other code that I have to write to provide my application logic, etc.
I see that Visual designer has generated the fiollowing code in the .ASPX file:
What about commands objects that were previously created in the code file? What about view and code separation idea? Are we going back to traditional ASP where everything was mixed in a simple .ASP file?
Thank anyone who can answer these me questions!
Jun 25, 2007 06:03 AM|naturehermit|LINK
Answer to your specific questions.
Question No 1....I hope I have understood you correctly.
Vs 2005 works on a system called partial classes ((in this case)meaning part of the class is resident in the .aspx code and part on the code behind and hence all the UI elements such as label etc (objects are no longer declared separately in code behind.).
You can therefore access those elements directly as if you were working in a class, so to access those object, their events for e.g.
say you have a label <asp:label runat="server" id=lbl"/>
u can access them directly like so lbl.text ="BLAH", because during compile time the stuff from both files is combined and then the compiler knows that there is a label and I need to set its text property or change its event.
You can double click on the object to generate its default event handler as well in the similar fashion.
Another functionality with VS2005 is that you can now, add many properties and events etc in the design view and clicking on the little arrow changes the studio in a wizard mode to do common tasks for you.
Question No 2.
Visual Studio 2005 offers so far in .net environment the most flexible code and UI separation. All that code that studio has generated for you is to make life easier, you can have all that code in code behind too. Now in Vs2005 you can have almost complete
seperation and what I mean by that is like in Vs2003 you had to create template columns etc for data controls, you can actually create your own controls and add them in the page runtime.
so for e.g.
<asp:textbox runat="server" id="txtbox"/> is actually control and not a pure html construct. You can now declare the same control in your code behind as
protected override void OnInit(EventArgs e)
TextBox txtName = new TextBox();
txtName.ID = "txtName";
txtName.Text = "Enter your name";
hence offereing a complete seperation. So some features are designed so that everyone can use the tool (remember the stuff about User interface metrics) but you can have almost 99% customizations and seperations.
Hope that helps and good luck