Spam isn't just an e-mail problem anymore. Web forms are now a
routine target of spammers. Whether your web site is a personal one
just looking for feedback or a commercial site generating sales
leads, getting dozens of entries for link exchanges or online
gambling sites isn't anyone's idea of useful feedback.
Hot on the heels of last week's Checkbox sample, this week, we're
covering the checkbox's closest relative: the radio button.
This sample code illustrates a number of different ways
to use both the HTML radio input type and the RadioButton
control from ASP.NET.
Although dealing with checkboxes isn't difficult, it can be
confusing. This sample code illustrates a number of different ways
to use both the HTML checkbox form element and the ASP.NET Checkbox
control. In addition to showing you how to set them up, it also
covers how to retrive data from each of them.
No it's not a typo... VB.NET's "ElseIf" really is different from
"Else If" and this difference can be very useful. It starts out
like any other "If Then," but there's no space between the "Else"
and the next "If."
While ASP.NET has some built in tools to aid in debugging, classic
ASP is relatively lacking in that regard. This tip will show you an
easy way to check the values of your application's variables and
then stop execution before you do any database writes or anything
else you might not want to do while testing.
Microsoft is offering Free E-Learning Courses for Visual Studio 2005.
Better hurry though... they're only free through November 17, 2005.
Be sure to register and order the courses you want today. Once
you order them you'll have access to the content for 90 days, but
they're only free for a very limited time!
It seems you can never make code simple enough. No matter how many
database related samples I publish, I'm always getting requests for
simpler ones. Well, this one is as simple as they get. This script
connects to our SQL Server database, executes a basic query, and
drops the results right into a DataGrid. You won't find any fancy
formatting or cool tricks in this sample, just straight-forward code
-- plain and simple.
The long road to Visual Studio 2005, SQL Server 2005, and the .NET
Framework 2.0 is finally winding down. Microsoft has just released
the final versions of these products to manufacturing. While VS.NET
and SQL Server 2005 are only available to MSDN subscribers, the .NET
Framework 2.0 and SDK are free for anyone to download.
Tired of sending plain text email messages from your website? Now
you don't have to... this sample will show you how to send email
messages that can be as lively as a web page from ASP.NET.
This script allows users to search for files simply by entering any
part of the filename. The implementation is easier then the classic
ASP version thanks to the fact that the GetFiles method of the
DirectoryInfo object will take an optional SearchPattern parameter
and handle the filtering for us.
I recently received an email from a visitor who wanted to know what
he could do when the number of files in a directory got too large to
be easily browsed via our original directory listing script. This
script is the result. It allows users to search for files simply
by entering any part of the filename.
Basic authentication has gotten a bad reputation over the years. So
it's not as flexible as forms authentication and not as secure as NT
Challenge Response, it has something going for it that neither of
these does - it's basic - as in simple!
One of our readers recently asked: "How do I display the file sizes
with commas between every third digit for numbers 1,000 and larger
in order to make the numbers easier to read?" While it's easy to
build a funtion to accomplish this task, luckily you don't need to.
After downloading the limited links version of our paged database
search script, one of our readers decided to send in an improved
implementation that wraps the code up into a function and adds some
CSS support. If you've ever wanted to be able to easily add
previous and next links to your search results, then have we got the
function for you.
This sample code shows you how to fill an ASP.NET DropDownList
control with site locations and have clients use it to navigate your
site. It includes both the client-side javascript and server-side
redirection code so that you can choose whichever you prefer.
In addition to the primary goal of programmatically creating and
adding server controls to a web form dynamically, this script also
illustrates a number of other cool .NET concepts including: using an
ArrayList to populate a DropDownList, building a string using a
StringBuilder, and hiding sections of a page using the Panel web
control.
Sometimes when you're getting input from users you know exactly what
to expect, but unfortunately that's not always the case. In cases
where you don't, you need to be flexible when designing the forms to
get this mystery data. This classic ASP script shows you how to
generate a number of form fields dynamically based on user input and
then read the values the user enters into those dynamically-generated
fields.
After trying out our paged database search script, one of our
visitors decided to send in an alternate version that doesn't
display a link to every result page, but instead creates a limited
set of links so that the display doesn't become unwieldy if your
database contains a large number of records.
This sample works just like our Database Sort sample except that it
adds the ability to sort by multiple fields just by clicking on the
field headings in sequence. The script will sort on as many fields
as you want but it does remove duplicates to keep things logical.
This is the ASP.NET version of our web logging script that will let
you add news links or other little entries to a section on a web
page. The section is displayed by including a text file in the page
that displays the entries. You add new entries to the include file
by simply filling out a web form.
This works just like our Database Sort sample except that it adds
the ability to sort by multiple fields just by clicking on the
field headings. The script will sort on as many fields as you want
but it does remove duplicates to keep things logical.
Here's a little web logging script that will let you add news links
or other little entries to a section on a web page. The section is
displayed by including a text file in the page that displays the
entries. You add new entries to the include file by simply filling
out a web form.
It can be useful to allow web users to download files from your site.
For many file types accomplishing this is trivial... just upload the
file and link to it. This works great for things like zip files,
setup programs, and many other file types that are simply downloaded
by browsers by default. But what if you want users to download a
file that browsers normally open?
This sample is the ASP.NET version of our classic ASP wizard. In
the classic ASP version, the bulk of the script's code dealt with
maintaining the form's state from page to page. Since ASP.NET
handles the viewstate for us, we're left to focus on the display of
the different pages and handling the button click events.
Sometimes when you're collecting data via a web form, it's nice to
split the form up into smaller pieces so that you don't overwhelm
the users who are filling them out. That's the idea behind wizards.
If you break long and/or complex tasks into smaller, easy to manage
pieces, users are less intimidated by them.
While you won't get the performance benefits you do with SQL Server,
you can use stored queries in Microsoft Access to move the query
text out of your ASP.NET code. In addition to helping you get used to
the idea of stored procedures, it might also help lessen your
vulnerability to SQL injection attacks.
I recently got an email from one of my contacts at Microsoft
announcing a new technology designed to make AJAX-style development
easier. We probably won't see a working copy until the PDC, but
it's nice to know something is at least in the works.
Carriage returns and line feeds don't count for much in HTML
documents, but there are times when they're useful. This sample
shows how to take a string and word wrap it to a certain length.
This should be extremely helpful for email message bodies or when
formatting with the <pre> tag.
For those new to programming or to ASP.NET, this sample shows you a
basic example of declaring a function and two different ways to call
it from your ASP.NET page.
Using the DataGrid's built in paging mechanism is a convenient and
easy way to implement paging, but as your database grows you may
notice a considerable delay while paging. The problem is that the
DataGrid doesn't just get the records for the current page... it
actually retrieves them all! This acticle shows you a more
efficient way to handle paging using some of the new features in SQL
Server 2005 and Microsoft's Enterprise Library.
Something you see in a lot of database access code is a select statement that
looks something like this:
SELECT * FROM TableName WHERE ...
While there's technically nothing wrong with it, using the SELECT * syntax
could be stealing away precious performance from your application, and even it
it's not now, it might someday soon.
As editor of a site that often deals with contributed content, over
the years I've converted quite a few Microsoft Word documents to
HTML format. While Word's "Save as Web Page..." does work, the
resulting HTML leaves quite a bit to be desired. Fortunately there
is a better way. While it's not perfect, this method is just as
easy and gives you a lot less bloat in the resulting HTML document.
Most variables that you deal with contain one value. Sometimes
however, it's useful to store more than one value at a time. Arrays
are one easy way to do this. This is an ASP.NET version of our
classic ASP Array sample. It's similar to our classic ASP version
with a few notable exceptions.
We've already shown you a couple ways to display XML file data on a
web page using an XSL stylesheet, but sometimes it's useful to take
it a step further and actually use the XML as a true data source.
This sample shows you how to use an XML file as the data source of
an ASP.NET DataGrid control.
Let's say you've got a lot of documents that you're finally trying
to get up on your web site. The only problem is, these were never
meant to be on a web site! They've got URLs in them, but they're
not hyperlinked and the thought of wading through all that text and
adding the appropriate links isn't something you're looking forward
to. Well then, this just might be the script for you...
We've all been faced with the problem of validating an email address
that a user has entered into one of our web forms. Too often the
email validation stops at simply checking that the text submitted
contains the "@" and "." characters, but for many applications this
really isn't good enough. This article starts by breifly explaining
the situation and then walks you through building a page that takes
an email address and checks its validity by performing a MX lookup
on the address's domain.
The above article introduces some code that allows you to validate
an email address by performing an MX Lookup on the its domain. This
article shows you how to use that code along with some other
tips and tricks to perform some really powerful form validation
using ASP.
Securing your web application against the hackers of the world is a
difficult task. One of the most common techniques of remotely
manipulating an application is parameter injection. This article
will demonstrate a simple method of checking for valid parameters in
an already written application.
This script is an ASP.NET version of our classic ASP Server.Execute
sample. While Response.Redirect gets the job done, you can often
accomplish the same tasks more efficiently using Server.Execute.
If you've been using ASP for any length of time, you've almost
certainly used Response.Redirect to move a user from one page to
another. While Response.Redirect gets the job done, it unfortunately
requires a round trip to the client browser. While there are some
situations where this is necessary, more often then not you can
accomplish the task more efficiently using Server.Execute.