I have several web pages, each of these pages is more or less the same. Each of them has a staff section at the top. The next section is the customer section, and the section is the previous orders. These two are not strictly necessary for all pages. The last section is comments (blogs).
I started with 2 pages, no problem. I wrote the same code (copy-paste) for each page (give or take a couple of details). Sales gave (made) it to the customer, and the customer got hungry. More MORE ... Now I have 10 pages with more or less the same code.
Now I was thinking if I could reduce development time by reusing the same βcontrolsβ. So, I started doing some ascx (4), thinking that I can reuse these 4 controls with each page (employee, customer, sales, blog).
I came across a little jerk, and Google tells me: "No, no, that's not how you use ascx." Ascx is just the new β asp:label β / β asp:textbox β, perhaps a bit more logic.
Snatch being - I did NewTest.aspx with each of the 4 controls, but I don't see asp:formview / asp:detailsview , etc. from the controls. I can put "hello worlds" around the form, just before, right after, but not inside the <formview></formview> .
Where am I mistaken that I need to review?
NewTest.aspx
<table width="800"> <tr> <td> <IIT:EmployeeRecord ID="test1" runat="server" /> </td> </tr> </table>
I use ObjectDataSource and pull the employee id from the session. The employee record is his name, a drop-down menu with his zipcodes (only salesrep) and a search field. Mostly text fields with a little extra logic.
All basic logic (BLL, DAL, Models, etc.) is exactly the same. The rest of the project compiles and works in exactly the same way as before you started working with ascx.
Edit: I try to get KSS this, if I can get EmployeeRecord to show, then I can copy this idea.
Run webconfig:
<pages> <controls> <add tagPrefix="IIT" tagName="Comments" src="~/DynamicData/FieldTemplates/Comments.ascx" /> <add tagPrefix="IIT" tagName="OrderRecord" src="~/DynamicData/FieldTemplates/OrderRecord.ascx" /> <add tagPrefix="IIT" tagName="CustomerRecord" src="~/DynamicData/FieldTemplates/CustomerRecord.ascx" /> <add tagPrefix="IIT" tagName="EmployeeRecord" src="~/DynamicData/FieldTemplates/EmployeeRecord.ascx" /> </controls> </pages>
Intellisense can recognize EmployeeRecord and OrderRecord, but not comments and CustomerRecord. Edit: Intellisense now recognizes them all.
EmployeeRecord
<asp:formview ID="fv_empDetail" runat="server" datasourceID="ods_empDetail"> <itemtemplate> <table> <tr> <td> Medarbejder: </td> <td> <asp:TextBox ID="tbEmployeeName" runat="server" ReadOnly="true" Text='<%# Bind("name") %>' BorderStyle="None"></asp:TextBox> </td></tr> </table> </ItemTemplate> </asp:FormView> <asp:ObjectDataSource ID="ods_empDetail" runat="server" SelectMethod="GetEmployee" TypeName="xxxxxx.EmployeeBLL"> <SelectParameters> <asp:SessionParameter Name="employee" DbType="String" SessionField="employee" /> </SelectParameters> </asp:ObjectDataSource>
(All typos are only for your pleasure;), there are no typos in the real code)