215 216 CHAPTER ■ CREATING A DNN MODULE Your code may be arranged a little differently, but it is the same code On this page, you have several DNN controls, including a text editor This text editor shows on the screen when you are on this page I don’t really want to get rid of anything on this page, in case I want it later on What I want to is disable some controls and let the administrator know that there is nothing to edit on this page I also only want the Cancel link to show at the bottom of the page There is one line of HTML code that I want you to put on this page It is a tag, and it is placed below the RequiredFieldValidator control The code is shown following, with the additional tag in bold: There is no content to edit. This is a simple addition to this page, which can easily be removed at a later date if necessary Now that you have this page done, you need to edit the code-behind page EditTimePunch.ascx.cs Open this file in the IDE, and the following: • Comment out every line in the cmdDelete_Click event handler • Comment out every line in the cmdUpdate_Click event handler • Comment out every line in the Page_Load event handler The cmdCancel_Click event handler will stay as it is You want the user to be able to cancel out of this page Add the following bold code to the Page_Load event handler: protected void Page_Load(System.Object sender, System.EventArgs e) { cmdUpdate.Visible = false; cmdDelete.Visible = false; ctlAudit.Visible = false; txtContent.Visible = false; CHAPTER ■ CREATING A DNN MODULE //try //{ } These four lines of code will make the controls on the page invisible Although you cannot compile your code right now, your page will look like that shown in Figure 7-19 Figure 7-19 The new Edit TimePunch page This should be plain enough The user can press the Cancel link at the bottom of the page and get back to the main page While you did not delete the ASP and C# code files lock, stock, and barrel, you did adjust them so that they fill your needs for now The last file to edit is the ViewTimePunch.ascx file Editing the Content Display Files The ViewTimePunch.ascx file will contain most of the code from the WebPunch project This is the file that shows everything to the user and accepts user input The first thing to here is to comment out all the code in this file This will allow you to compile the website and see how the TimePunch module looks so far Do the following: • Comment out the code inside the Page_Load event handler (located in the Event Handlers region) • Comment out the code in the lstContent_ItemDataBound event handler (located in the Event Handlers region) 217 218 CHAPTER ■ CREATING A DNN MODULE Since this is the last file you need to edit, commenting out this code should enable the DNN website to compile and run Press Ctrl+F5 and see if the module compiles It should If it does not, and you cannot easily debug it, I suggest that you take the following code files (available from the Apress website) and replace yours with mine • EditTimePunch.ascx and EditTimePunch.ascx.cs • ViewTimePunch.ascx and ViewTimePunch.ascx.cs • TimePunchController.cs • TimePunchInfo.cs • DataProvider.cs • SqlDataProvider.cs If the module compiles, it should work The only thing that would prevent the module from compiling is passing incorrect arguments to methods, or calling methods that not exist anymore Figure 7-19 shows what happens when you press the Add Content link Adding Content Now it is time for dessert You will be adding code from the WebPunch program into this file, and the page that you want will appear Open the ViewTimePunch.ascx file in source mode Your screen should look like Figure 7-20 Figure 7-20 The ViewTimePunch.ascx file, before editing Since this page is a control (as evidenced by the first line of code here), there will not be any HTML header or form tags What you have in here instead is an ASP datalist control If you are interested in this control, I encourage you to look it up in the help However, you will not need it, so I won’t explain it Start up another instance of VWD You can have as many instances open as you want In this new instance of VWD, open the WebPunch program Select everything between the CHAPTER ■ CREATING A DNN MODULE tags, including the tags themselves, and copy this to the clipboard, as shown in Figure 7-21 Figure 7-21 Selecting and copying the WebPunch tag contents to the clipboard Now go back to the TimePunch IDE where you have the ViewTimePunch.ascx file open in source mode Select the datalist tags and everything in them, as shown in Figure 7-22 Figure 7-22 Selecting the ViewTimePunch datalist tags 219 220 CHAPTER ■ CREATING A DNN MODULE Press Ctrl+V to copy the tag information in place of this datalist tag information You should now have the design code from the WebPunch program in your TimePunch module Inside the ViewTimePunch.ascx.cs C# code file, delete the lstContent_ItemDataBound method There is no longer any such control to fire this event Before you insert the code behind all this design, I want to just stub in the missing event handlers and test the look of the page In the ViewTimePunch.ascx.cs file, put the following code: protected void cmdPunch_Click(object sender, EventArgs e) { } protected void cmbWeek_SelectedIndexChanged(object sender, EventArgs e) { } Adding this code prevents any compiler errors Press Ctrl+F5 to build and show the website Once the website comes up, log in as admin and click the Time menu choice Your screen should look like the one shown in Figure 7-23 Figure 7-23 The TimePunch module with WebPunch design code CHAPTER ■ CREATING A DNN MODULE Oops! What happened here? Before I tell you, I think you should try to figure it out just from this picture It looks like the WebPunch controls are not inside the module, but all over the page itself Resize the browser, and everything moves except these controls It is almost like they are in a fixed position Aha! All the controls for the WebPunch program are in a fixed position, as evidenced by the position: absolute; style attribute in each control I mentioned in a previous chapter that when you are starting to create web pages, it is best to start with absolute positioning Unfortunately, this has come back to bite you The best way to fix this is to use an HTML table within the control and place each of these WebPunch controls within the table’s cells Creating a Table An HTML table is a good fit for arranging the controls in the TimePunch module If it is done right, the controls will move and resize properly according to the control itself Now that you’ve copied all the WebPunch controls over here, I want you to delete them from this page You will need to add a table and then add the controls one at a time Right now, your ViewTimePunch.ascx file should have only these lines in it: The table you need will have to have cells to hold each control individually Since you have six rows of controls, you need at least six rows in the table By the time you are done, though, you will have added a few more rows just to add some vertical filler space around the Punch button There are two ways to add a table to the designer One is to drag a table control from the toolbox and give it some columns and rows This has the disadvantage of being a perfect table with an equal number of cells in each row You not want this for reasons you will see in a bit Add the following code to your page: This HTML code adds a table whose width and height take up 100 percent of the container In this case, the container is the module As the module gets resized, so does the table Using a table this way is really the best way to set up a page that can be resized by the user but still keeps the controls relative to each other I always start out all tables with a border of This forces the row and column lines to show, and it makes it easier to see how the table is laid out on the page When I am done, I change the border to 221 222 CHAPTER ■ CREATING A DNN MODULE The tag is a table row I made this row the same width as its container, which is the table itself I also made the vertical alignment of controls within this row to be in the middle A table row is no good without having some table cells inside of it So you would think that the table cell tag would be right? Wrong It is , which stands for table data Add a couple of cells to the table, and you should get the following code: The tags have an attribute called colspan Remember I said that you not want an even number of cells in each row of this table? In fact, the maximum number of cells you need in any row is seven This corresponds to the number of days in a week I have two cells in this row, so I make the width of the first cell equal to the width of two cells I then make the width of the next cell equal to the width of five cells Now these two cells take up the same space as the seven cells The row I will have you put below this one will have seven sets of tags whose total width will be equal to 100 percent of the width of the table Here is how the table code will look: ... procedure is taking columns from two tables and combining them before giving back the data It is doing an inner join, in which it takes the UserID it finds in the TimePunch table and looks inside the... The new region is shown following, with the changed lines in bold: #region Private Members private private private private private private int int int int DateTime string _ModuleId; _ItemId; _PunchType;... The files you will be editing in this section are TimePunchInfo.cs and TimePunchController.cs Editing TimePunchInfo.cs This file contains a single class that holds the information for any particular