开发者

Am I on the right track (ASPX, ascx, design)

I have several webpages, each of these 开发者_如何学JAVApages are more or less the same. Each of them have a employee section at the top. Next section is the customer section, and section after is previous orders. These two are not strictly necessary on all pages. Last section is comments (blogging).

I started out with 2 pages, no problem. I wrote the same (copy-paste) code for each page (give or take a couple of details). Sales gave(baited) this to the customer and the customer got hungry .. more more MORE... Now I have 10 pages with more or less the same code.

Now I was thinking can I reduce dev time by reusing the same "controls". So started doing some ascx (4), thinking I could reuse these 4 controls with each page (employee, customer, sales, blog).

I run into a little snatch and google tells me - "no no no that is not how you use ascx". An ascx is merely a new "asp:label" / "asp:textbox" with perhaps a little extra logic in.

Snatch being - I made a NewTest.aspx with each of the 4 controls in, but I'm not seeing the asp:formview / asp:detailsview etc from the controls. I can put "hello worlds" all around the formview, just before, just after - but not inside the <formview></formview>.

Where am I going wrong, what do I need to reconsider?

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 Session. The Employee record - His name, a dropdown with his zipcodes(salesrep only) and a search field. Basicly a textbox(es) with a little extra logic.

All the underlying logic (BLLs, DALs, Models, etc) are precisely the same. Rest of the project compiles and runs precisely the same as before I started with the ascx's.

Edit: I'm trying hard to KSS this, if I can get EmployeeRecord to show, then I can copy-paste that idea.

Start in 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 recognise EmployeeRecord and OrderRecord, but not Comments and CustomerRecord. Edit: Intellisense now recognises 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>

(Any typos are for your pleasure only ;) , there are no typos in the real code)


Use MasterPage for your project. If you think that there are information for some common specific group of pages irresective of other groups, then use a nested master page for those specific groups of pages.

Using nested masterpages will keep your root masterpage light, and will serve for other pages too.

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

Create ASP.NET user control

My User Control


Why not create a master page that contains all the information common to all pages and then only fill in the information that is page specific?


If I have understood your problem correctly, what you are trying to do is to place Web controls (custom or otherwise) within your own custom controls.

I think what you are trying to do is to create templated ASP.NET controls. Please see the article How to: Create Templated ASP.NET User Controls.

This will enable you to write something like the following in 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 has been adapted from the article linked to above.

Notice how two asp:Label tags exist inside the MessageTemplate element of the uc:TemlpateTest.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜