Using Aspnet Components

The e-mail format can either be HTML format or Text format. Because some e-mail clients will not format HTML files, you may wish to send e-mail in Text format. Many sites allow the user to specify whether they wish to receive e-mail in HTML or Text format.

You can let the user select the priority of the e-mail message with a drop-down list box. See ASPMail_ai.aspx on the CD for an example of using this in a full aspx page.


String stringMailPriority =


switch(stringMailPriority) { case "High":

mailmessageSuggestion.Priority = MailPriority.High; break; case "Normal":

mailmessageSuggestion.Priority = MailPriority.Normal; break; case "Low":

mailmessageSuggestion.Priority = MailPriority.Low; break; default:

mailmessageSuggestion.Priority = MailPriority.Normal; break;

Untitled - Notepad

File Edit Format Help jsjx]

ImportNamespace-'System.Web.Mail" %> <HTML> cHEAD>

<SCRIPT LANGUAGE-'C#" RUNAT-"Setver"> void SubmitBtn_Cllck(object Source, EventArgs e) { string strlngMessage - ""

stringMessage - "«FONT FACE-Verdana'>My suggestion Is for" ■ dropdownllstSuggestlons.Selectedltem.Text + "</FONT>";

MailMessage mailmessageSuggestion - new MallMessage(); mailmessageSuggestion.From - "[email protected]", mallmessageSuggestion.To = "[email protected]"; mailmessageSuggestion Subject - "Suggestion";

mailmessageSuggestion Body - strinqMessaqe;!_

mallmessaqeSuqqestion.BodvForrnat = MailForrnat.Htmil

SnitpMail.Send(mailmessaoeSuqqestionl:t labelMessage.Text -"Your suggestion Is dropdownlistSuggestions.Selectedltem.te>! + ". An email has been sent to our company president.


_Q Set the Body property for the MailMessage, using the string variable in which you have placed the message.

Set the BodyFormat property for the MailMessage to MailFormat.Html.

Add the SMTPMail's Send method to send the message.

Update the Text property for the label on the page to reflect that the mail has been sent.

^ Save the file and request from the Web server.

■ The page with suggestions appears.

£ Click the Submit button.

■ The page with suggestions appears.

Click 0 and select a suggestion.

£ Click the Submit button.

■ The message appears, notifying you of the e-mail's status.


One way of increasing performance for your ASP.nEt Web pages is to cache pages on the Web server. When using a page cache, ASP.NET does not generate a new response for a Web page every time it is requested. This performance optimization can be used on pages that are accessed frequently and or have little to no personalization on them.

The process for setting up page caching is simple. On the page you wish to cache, add an OutputCache directive at the top of the page and add a Duration attribute for the directive. The Duration will specify how long to cache the page in seconds. There will be cases when you may want a page generated based on the request made. For example, you may want to have another version of the page generated when something varies in the request's query string.

When caching pages, ASP.NET is smart about sending cached pages. For example, if a page is requested with a query string that is different from the cached page, then ASP.NET will regenerate the page and cache this new page (keeping the original page cached). The next time the page is requested, it will check to see whether that version of the page is cached before reprocessing the page.


% Untitled - Notepad

File Edit Format Help

Q Open the

DatagridTemplate.aspx template from the Code Templates directory.

<%@ImportNamespace-'System.Data" %> =%@ Import Namespace-'System.Data.SqICIIent" %> <HTML> =HEAD>

<SCRIPT LANGUAGE="C#" RUNAT="Server"> protected void Page_Load(Object sender, EventArgs e) {

SqIConnectlon sqlconnectlonPubs = new SqlConnection("server=(local)\\NetSDK;uid=QSUser;pwd=QSPassword;databa! s").

SqIData Adapter sqldataadapterTitles = new SqiDataAdapterfselect t notes, price from titles where type-business1" sqlconnectlonPubs); DataSet datasetTltles = new DataSetQ, sqldataadapterTitles.FIII(datasetTltles, "titles"); datagrldTltles.DataSource=datasetTitles.Tables["tltles"].DefaultVlew; datagrl dTltles.DataBi nd();

=FOMT FACE ="Verdana">

-H Add the OutputCache directive to set the duration of the page cache to 60 seconds.

-H Add the OutputCache directive to set the duration of the page cache to 60 seconds.

Add a message to the page by updating the label with the current time.

Note: The page-generation message will update only when the code in the Page_Load function is run.

□ Save the file and request it from the Web server.

Was this article helpful?

0 0

Post a comment