I'm on the right track (aspx, ascx, design)

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)

+4
source share
3 answers

Use MasterPage for your project. If you think that there is information for some common page groups that are not sensitive to other groups, use the sub-page for these groups.

Using nested master pages will contain the title of the main page, and will also be displayed on other pages.

You can also follow the link for developing the user control given by @Umar, or refer to the following:

Create an ASP.NET User Control

My user control

+2
source

Why not create a master page containing all the information common to all pages, and then fill in only the information related to the page?

0
source

If I understand your problem correctly, what you are trying to do is place the web controls (user or others) inside your own user controls.

I think you are trying to create ASP.NET boilerplate controls. See Article How to Create ASP.NET Template User Controls .

This will allow you to write something like the following to your .aspx / ascx files.

 <uc:TemplateTest runat="server"> <MessageTemplate> <asp:Label runat="server" ID="Label1" Text='Foo!!' /> <br /> <asp:Label runat="server" ID="Label2" Text='Bar!!' /> <hr /> </MessageTemplate> </uc:TemplateTest> 

NB: this example was adapted from an article related to the above.

Note that two asp:Label tags exist inside the MessageTemplate uc:TemlpateTest .

0
source

All Articles