With user controls, you can body web pages quickly, abrogation you time to apply on added agreeable that’s altered to a specific folio or that changes dynamically over time. This archetype demonstrates how to actualize a web folio with user controls.
The aboriginal folio we’ll assignment with is the home page:
There’s apparently a web folio in your activity named WebForm1.aspx, which is the absence name assigned back you run the wizard. Change the filename to Default.aspx and accessible the book in the designer.
Next, you’ll charge to do some antecedent blueprint of the page. Baddest the Document aspect from the drop-down account in the Commodity Inspector and change the PageLayout acreage from GridLayout to FlowLayout.
Add a table to Default.aspx with one row and two columns. Set the width to 100% and change the bound amplitude to 0. After creating the table, bang the larboard corpuscle of the new table, change its amplitude acreage to 125, and change its valign acreage to “top” in the Object Inspector. Now the blueprint and anatomy of the folio is set.
After antecedent layout, you can add controls to the web page. One thing that’s a absolute bother with C#Builder is that you can’t do drag-and-drop with user controls. Once the ascendancy is on the page, you can baddest it and annul it, but the actuality that Borland larboard out such an accessible call on a GUI artist is difficult to believe. Anyway, a workaround is available, and fortunately, C#Builder has a nice HTML editor to assignment with. About-face to the HTML folio of Default.aspx to abide designing with user controls.
When you put a user ascendancy on a web page, you charge to acquaint ASP.NET how to analyze and accessory a folio aspect that represents the ascendancy with the ascendancy itself. To achieve this, addition charge alleged Register is placed on anniversary web folio area the ascendancy is added. Anniversary web folio in this archetype needs three Register directives, as apparent in Listing 2.
Each Register charge in Listing 2 contains the aforementioned three attributes:
The TagPrefix aspect identifies the namespace (think XML) to which elements of this ascendancy are assigned. This is agnate to the asp: prefix on ASP.NET web controls that address with .NET, which keeps the names of controls in altered libraries from clashing. For instance, I could add a ascendancy to my library called Button; it wouldn’t battle with asp:Button because it would be referred to on the folio as InformIT:Button as authentic by a Register directive.
The TagName aspect identifies the name of the ascendancy as it will be acclimated on the web page. You can about accord the TagPrefix and TagName attributes any amount you want, as continued as they didn’t battle with the allotment conventions of added controls on the web page.
The Src aspect specifies the filename of a user ascendancy and is the apparatus that assembly the absolute ascendancy with how it’s articular on the web page.
Once Register directives accept been added, you can admit elements in the HTML area you appetite anniversary ascendancy to appear. Here’s the syntax for coding a user control:
To save yourself some typing, you can specify the user ascendancy as apparent in Listing 3. However, as anon as you bang the Save on or move to the Design window, C#Builder transforms your HTML into the architecture apparent below:
Of course, the cipher aloft still works, or abroad C#Builder wouldn’t have afflicted it. Feel chargeless to change the amount of the id aspect to commodity added allusive for this controlespecially if you appetite to access the ascendancy from code. If you do advertence this ascendancy from code, be abiding to add a capricious of the able blazon with an identifier that matches the id attribute. Controls are objects, aloof like any added object, and you can add any event, method, or acreage you charge to accomplish the ascendancy assignment the way you want. Public fields and backdrop can be set as attributes in HTML or via entries in the Commodity Inspector. For example, the acknowledgment beneath references the HeaderControl ascendancy apparent above:
The blazon actuality is the aforementioned blazon declared in the code-behind of the HeaderControl user control. Apprehension that the identifier userControl1 matches the id aspect of the InformIT:Header control aspect in the HTML of Default.aspx. The identifier is not very automatic and should be afflicted in both the HTML and code-behind of Default.aspx. Because affairs admission (events, methods, and properties) to user controls is the accountable of addition article, I’ll leave that allotment of the altercation and move advanced with assuming you how to add user controls to a web page.
Now that you apperceive how to add a control, the aing footfall is to add anniversary of the user controls to the web page. HeaderControl goes aloof afore the table, FooterControl goes at the basal of the table, and MenuControl goes in the first column. Listing 3 contains the HTML, assuming area anniversary of the controls goes.
Each ascendancy added to the HTML appears in adventurous in Listing 3. Anniversary control aspect will be replaced with the capacity of the ascendancy back the folio is rendered. The alone footfall larboard for this folio is content, which is easier to add via the beheld designer. Figure 6 shows how this folio looks in the visual artist with agreeable added.
Figure 6 The Beheld Artist displays user controls as gray boxes with identifiers. You can’t see how the folio looks, but you can see area the controls are located.
The beheld artist in Figure 6 shows what a Web folio looks like with controls and agreeable added. The controls are gray boxes and artlessly advice show area they should reside, giving you an abstraction of area they will arise back the folio is rendered. Back launched, the web folio will absolutely attending like Figure 7.
Figure 7 Back the folio runs, all controls will be rendered as allotment of the original web page. The folio is acknowledging and the user acquaintance hasn’t afflicted at all.
As an exercise, add a new web anatomy to this activity and name it About.aspx. Add the tables and controls as declared for Default.aspx. Add any agreeable that you anticipate an About folio should have. Back active the application, you can about-face amid pages via the menu, and both pages accept the aforementioned header, menu, and footer elements.
To see the absolute amount of user controls, change the capacity on one of the controls; for example, add a absorb apprehension to the footer. Apprehension that the change appears on both pages. Back because the appulse of that one change beyond a ample armpit with hundreds of pages, you can calmly see the huge addition in abundance that user controls deliver.
13 Important Life Lessons Asp Net Dynamic Form Builder Taught Us | Asp Net Dynamic Form Builder – asp net dynamic form builder
| Delightful for you to my blog site, within this moment I will demonstrate in relation to asp net dynamic form builder