Using the Generic Button in the WorkOrder Form


We have created a generic button to display a "quick entry" form, but so far we have not used it anywhere . In this section you'll learn how to use the generic button in the WorkOrder form.

To do so, you're going to change the New buttons currently on the form that are of type Button to NewButton, the class you created in the previous section.

To replace all buttons on the WorkOrder form with NewButton:

  1. Open the WorkOrder form in the designer and click the designer's HTML button to display the HTML for the form ( Figure 5.36 ).

    Figure 5.36. We need to switch to HTML view in the editor in order to add information for our custom control to the form.

    graphics/05fig36.gif

  2. After the line that <%Page...%> add the <%Register...%> tag from Figure 5.37 . This line tells ASP.NET that there are custom controls in our project. To use the custom control all we have to do is use the tag we registered with the <%Register...%> directive. In this case the tag is SuperControls.

    Figure 5.37 The Register directive registers a new tag that will represent our custom control. Whenever you use one of the standard controls, you use the < asp:control> tag. In this line we are registering <SuperControl:control> for our custom control.
     <%@  Register  TagPrefix="SuperControls"     Namespace="inheritanceproject"     Assembly = "inheritanceproject" %> 
  3. Replace the HTML for the two buttons on the form with the HTML in Figure 5.38 . Notice that this HTML uses SUPERCONTROL:NEWBUTTON for the tag name rather than asp:Button. The SuperControl portion of the tag comes from the Register command in step 2 and tells ASP.NET that the control comes from our own DLL; and the NewButton part of the tag tells ASP.NET the class name of the control which is NewButton. The two new entries also set the Control property of the New button to the listbox control next to the buttons.

    Figure 5.38 All we have to do to turn the standard button control into our control is to change the asp:button tag to SuperControl:NewButton. Also we can add an attribute for the Control property of NewButton.
     <%@ Page language="c#"    Codebehind="WorkOrder.aspx.cs"    AutoEventWireup="false"    Inherits="inheritanceproject.WorkOrder" %> <HTML>    <HEAD>          <title>WorkOrder</title>    </HEAD>    <body MS_POSITIONING="GridLayout">    <form id="WorkOrder" method="post"                 runat="server">    <asp:label id="lblBldg"               style="Z-INDEX: 101; LEFT:               22px; POSITION: absolute;               TOP: 23px" runat="server"               Height="22px" Width="61px">               Building:               </asp:label>    <asp:label id="lblDepartment"               style="Z-INDEX: 106; LEFT:               23px; POSITION: absolute;               TOP: 55px" runat="server"               Height="22px" Width="61px">               Department:               </asp:label>    <asp:dropdownlist id="lstBuilding"               style="Z-INDEX: 102; LEFT:               113px; POSITION: absolute;               TOP: 23px" runat="server"               Height="26px"               Width="176px">               </asp:dropdownlist>    <asp:dropdownlist id="lstDepartment"               style="Z-INDEX: 103; LEFT:               113px; POSITION: absolute;               TOP: 55px" runat="server"               Height="26px"               >Width="176px">               </asp:dropdownlist>  <SUPERCONTROLS:NEWBUTTON   id="btnNewBldg"  style="Z-INDEX: 104; LEFT:               299px; POSITION: absolute;               TOP: 23px" runat="server"               Height="21px" Width="61px"               Control="lstBuilding">  </SUPERCONTROLS:NEWBUTTON>   <SUPERCONTROLS:NEWBUTTON   id="btnNewDept"  style="Z-INDEX: 105; LEFT:               299px; POSITION: absolute;               TOP: 56px" runat="server"               Height="21px" Width="61px"               Control="lstDepartment" >  </SUPERCONTROLS:NEWBUTTON>  </form>    </body> </HTML> 
  4. In the code for the WorkOrder form, replace the field declarations for the two buttons with the code in Figure 5.39 . This code changes the variable types from System.Web.UI.WebControls .Button to NewButton.

    Figure 5.39 All that is left to do is replace the fields in our WorkOrder class that the wizard generated to be of type NewButton instead of Button.
     //using System.Web.UI.WebControls protected Label lblBldg; protected DropDownList lstDepartment;  protected NewButton btnNewDept;   protected NewButton btnNewBldg;  protected Label lblDepartment; protected DropDownList lstBuilding; 

graphics/tick.gif Tips

  • In this section, we told ASP.NET about our control by adding a Register tag to the HTML of the WorkOrder form. We can then use the new button by using this new tag in the HTML. The last step was to make sure that the variables that represent our buttons in the code were changed to NewButton types instead of Button.

  • The application is now finished and should be fully functional. Experiment by clicking the "New" button next to the Building listbox, then adding a new Building name in the quick entry form and pressing Save. The new entry should appear in the Building listbox.




C#
C# & VB.NET Conversion Pocket Reference
ISBN: 0596003196
EAN: 2147483647
Year: 2003
Pages: 198
Authors: Jose Mojica

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net