Common Tasks in WebForms
Common Tasks in WebForms
DetailsView
FormView
How do I
You must bind every parameter to the source of that parameters information.
o For example, if the user has entered data, bind a control.
o If the data is related to the page, which receives a request argument, then you will
probably bind to a QueryString parameter.
o If the data is related to the logged in user, you might need to bind to a Session
variable, perhaps for UserID.
Place an Add button to add the data to the database.
Attach an event handler to the Add button.
Write the code to perform the insert query.
On a successful insert, you will probably want to redirect to the current page to force a
refresh of displayed content.
if (dataSource.Insert() > 0)
{
// Insert is successful!
Response.Redirect(Request.Url.AbsoluteUri);
}
else
{
// Insert made no changes.
}
// Wrap this code in a try-block to catch exceptions.
// Exception handling is covered in a different module.
After a user logs in, you must store their credentials in a Session variable.
The presence of that Session variable is an indication that the user is logged in.
Session.Clear();
Response.Redirect(Request.Url.AbsoluteUri);
Note that the redirect is not optional. You must redirect after installing or removing the
session. The reason is that you must force a cookie change in the browser, so redirect to
ensure the change to the cookie happens.