Database Storage with the ASP.NET Web Matrix: Unsubscribe Page - Setting up the Page
(Page 2 of 4 )
Use the Properties pane in the bottom-right of the application to set the text of the first label control to Username: and the ID of the textbox to txtUsername. Set the ID of the label following the textbox to lblUsernameError, change the color to red and clear the Text property. This control will display an error if the username entered does not appear in the database. Next, set the ID and Text properties of the button to btnSubmit and Submit respectively. The final label will be used to display a message when the action is successful, so change the Forecolour property to Green and the ID to lblSuccess. Remove the Text property. The page should look a little like this:

You will notice that we are not asking the user for their password, only their username. The reason for this is that we are also going to implement an authentication system that uses a session cookie to determine whether a user has already logged in to the site. If a user is not logged in, we will not let them access the unsubscribe page, and will instead redirect them to the login page that was created in the last article. The username field is still needed in this case in order to specify the string used in the database query. This is not the only way to do it; we could for example use the session cookie to store the username and read from this instead.
The security aspects will be discussed later. For now, switch to the Code view of the Web Matrix, and we can build the logic of the page. The toolbox will automatically change to the code wizards. Drag the DELETE Data Method onto the page to open the DELETE Data Code Wizard. Make sure that the database we’ve been working with so far is highlighted on the first page and click Next. On the second page of the wizard, click the Where button to open the Where clause builder dialog box and just click Ok to accept the default. A preview of the Where clause and data operation will be shown:

Click the Next button twice and in the final screen of the wizard, enter a name for the function like removeUser, before clicking the Finish button. This will insert the code needed to remove entries from the database. All you need now is a way of calling the function you have just created.
Next: Calling the Function >>
More ASP.NET Articles
More By Dan Wellman