14 July 2007

CSS tabbed menu with submenus



The CSS styles:


/*** GLOBAL ***/

HTML {
cursor: default;
}



/*** MENU ***/

DIV#MenuManagerDiv {
width: auto !important;
height: auto !important;
text-align: left !important;
vertical-align: top !important;
margin: 0px 0px 0px 0px; /* T R B L */
padding: 0px 0px 0px 0px; /* T R B L */
}

UL.MenuList {
display: block !important;
list-style-type: none;
margin: 0px 0px 0px 0px; /* T R B L */
padding: 0px 0px 0px 0px; /* T R B L */
text-align: center;
}

LI.MenuListItem {
list-style-type: none;
float: left;
}

LI.MenuListItem > DIV.CaptionWrapper {
/* Set the Menu Caption width */
width: 80px;
height: auto;
display: block;
text-align: center;
}

DIV.CaptionWrapper:hover > SPAN.CaptionText {
font-family: Verdana, Sans-Serif;
font-size: 9pt;
color: #ff0000; /* Red */
}

SPAN.CaptionText {
font-family: Verdana, Sans-Serif;
font-size: 9pt;
color: #030; /* Green */
}


/************************************** SUBMENUS ***/

TABLE.GlobalSubmenuContainer {
display: none;
}
TD.GlobalSubmenuWrapper_Cell {
background-color: #FFFFDC;
color: #000; /* Black */
border: solid 1px #ff9900;
padding: 2px 2px 2px 2px; /* T R B L */
cursor: hand;
}

/**............................... PRODUCTS SUBMENU **/
TABLE.SubmenuWrapper_Products {
/* the table width must be set */
width: 300px;
}
A.ProductsSubmenuLink:link, A.ProductsSubmenuLink:visited {
font-family: Verdana, Sans-Serif;
font-size: 9pt;
color: #000; /* Black */
text-decoration: none;
}
A.ProductsSubmenuLink:hover {
font-family: Verdana, Sans-Serif;
font-size: 9pt;
color: #FF0000; /* Red */
text-decoration: underline;
}

/***.............................. SHOW / HIDE THE PRODUCTS SUBMENU ***/
DIV.CaptionWrapper:link > TABLE.SubmenuWrapper_Products {
display: none;
}
DIV.CaptionWrapper:visited > TABLE.SubmenuWrapper_Products {
display: none;
}
DIV.CaptionWrapper:hover > TABLE.SubmenuWrapper_Products {
display: block;
}




/**............................... SERVICES SUBMENU **/
TABLE.SubmenuWrapper_Services {
/* the table width must be set */
width: 300px;
}
A.ServicesSubmenuLink:link, A.ServicesSubmenuLink:visited {
font-family: Verdana, Sans-Serif;
font-size: 9pt;
color: #FF0000; /* Red */
text-decoration: none;
}
A.ServicesSubmenuLink:hover {
font-family: Verdana, Sans-Serif;
font-size: 9pt;
color: #000; /* Black */
text-decoration: underline;
}

/***.............................. SHOW / HIDE THE SERVICES SUBMENU ***/
DIV.CaptionWrapper:link > TABLE.SubmenuWrapper_Services {
display: none;
}
DIV.CaptionWrapper:visited > TABLE.SubmenuWrapper_Services {
display: none;
}
DIV.CaptionWrapper:hover > TABLE.SubmenuWrapper_Services {
display: block;
margin-left: -80px; /* minus the width of the first DIV.CaptionWrapper */
}


The XHTML:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">

<head>

<title>CSS tabbed menu with submenus</title>

<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />

<link href="MasterStyleSheet.css" media="screen" rel="stylesheet"
type="text/css" />

</head>

<body>

<div id="MenuManagerDiv">

<ul class="MenuList">

<li class="MenuListItem">

<div class="CaptionWrapper">

<span class="CaptionText">Products</span>

<table cellpadding="0" cellspacing="3" class="GlobalSubmenuContainer
SubmenuWrapper_Products">

<tr>

<td class="GlobalSubmenuWrapper_Cell">

<a class="ProductsSubmenuLink" href="#">Product 1</a></td>

<td class="GlobalSubmenuWrapper_Cell">

<a class="ProductsSubmenuLink" href="#">Product 2</a></td>

<td class="GlobalSubmenuWrapper_Cell">

<a class="ProductsSubmenuLink" href="#">Product 3</a></td>

</tr>

</table>

</div>

</li>

<li class="MenuListItem">

<div class="CaptionWrapper">

<span class="CaptionText">Services</span>

<table cellpadding="0" cellspacing="3" class="GlobalSubmenuContainer
SubmenuWrapper_Services">

<tr>

<td class="GlobalSubmenuWrapper_Cell">

<a class="ServicesSubmenuLink" href="#">Service 1</a></td>

<td class="GlobalSubmenuWrapper_Cell">

<a class="ServicesSubmenuLink" href="#">Service 2</a></td>

<td class="GlobalSubmenuWrapper_Cell">

<a class="ServicesSubmenuLink" href="#">Service 3</a></td>

</tr>

</table>

</div>

</li>

</ul>

</div>

</body>

</html>




To add another Tab Menu and Submenus to the current menu, append this list item code block to the existent list showed above:

<li class="MenuListItem">
<div class="CaptionWrapper">
<span class="CaptionText">Another</span>
<table cellpadding="0" cellspacing="3" class="GlobalSubmenuContainer SubmenuWrapper_Another">
<tr>
<td class="GlobalSubmenuWrapper_Cell">
<a class="AnotherSubmenuLink" href="#">Another 1</a></td>
<td class="GlobalSubmenuWrapper_Cell">
<a class="AnotherSubmenuLink" href="#">Another 2</a></td>
<td class="GlobalSubmenuWrapper_Cell">
<a class="AnotherSubmenuLink" href="#">Another 3</a></td>
</tr>
</table>
</div>
</li>


When you add another code block as the one above, you should rename:

- the table second class
- the links class name (if you want it to look different)


and add another code block in the css file:

/**............................... ANOTHER SUBMENU **/
TABLE.SubmenuWrapper_Another {
/* the table width must be set */
width: 300px;
}
A.AnotherSubmenuLink:link, A.AnotherSubmenuLink:visited {
font-family: Verdana, Sans-Serif;
font-size: 9pt;
color: #FF0000; /* Red */
text-decoration: none;
}
A.AnotherSubmenuLink:hover {
font-family: Verdana, Sans-Serif;
font-size: 9pt;
color: #000; /* Black */
text-decoration: underline;
}

/***.............................. SHOW / HIDE THE Another SUBMENU ***/
DIV.CaptionWrapper:link > TABLE.SubmenuWrapper_Another {
display: none;
}
DIV.CaptionWrapper:visited > TABLE.SubmenuWrapper_Another {
display: none;
}
DIV.CaptionWrapper:hover > TABLE.SubmenuWrapper_Another {
display: block;
margin-left: -160px; /* minus the width of the first DIV.CaptionWrapper and the width of the previous DIV.CaptionWrapper */
}







This code was tested in:
- FireFox 2.0
- Opera 9
- IE 7

04 May 2007

Really easy CSS Menu


When you start creating your website your first thought when it comes to the menu is to use a table.

Well, you can create a table for the menu, there's nothing wrong with that, but using tables isn't always the best choise.

So, this is an example where I'm using an unordered list (ul), to create my menu:


 <div id="MenuListContainer">
<ul>
<li><a href="#">Home Page</a></li>
<li>|</li>
<li><a href="#">Resources</a></li>
<li>|</li>
<li><a href="#">Webmasters</a></li>
<li>|</li>
<li><a href="#">Terms</a></li>
<li>|</li>
<li><a href="#">About</a></li>
<li>|</li>
<li><a href="#">Contact</a></li>
</ul>
</div>



As you can see, using the unordered list become more easily to deploy and configure your menu.


The CSS styles to use are the following:

<style type="text/css" media="screen">
div#MenuListContainer {
width: auto;
height: auto;
text-align: left;
vertical-align: top;
margin: 0px 0px 0px 0px; /* T R B L */
padding: 0px 0px 0px 0px; /* T R B L */
}

div#MenuListContainer ul {
display: inline;
list-style-type: none;
margin: 0px 0px 0px 0px; /* T R B L */
padding: 5px 5px 5px 5px; /* T R B L */
background-color: #eeeeee;
}

ul li {
display: inline;
margin: 0px 0px 0px 0px; /* T R B L */
padding: 5px 5px 5px 5px; /* T R B L */
font-family: Georgia, Serif;
font-size: 10pt;
color: #000000;
text-align: center;
line-height: 1.6em;
}

li a:link {
color: #000000;
text-decoration: none;
}
li a:visited {
color: #696969;
text-decoration: none;
}

li a:hover {
color: #8b0000;
text-decoration: none;
}
</style>


And this is how it looks in IE7:


02 May 2007

Light Up the Web




Last night I watched Scott Guthrie (General Manager @ Microsoft) and Ray Ozzie (Chief Software Architect @ Microsoft) presenting Silverlight.
That was a 2 & 1/5 hours of interesting material about this new technology that Microsoft just released.

"In an address from Las Vegas at the MIX07 Web conference, Chief Software Architect Ray Ozzie and Developer division General Manager Scott Guthrie will discuss the full breadth of Microsoft’s developer vision and roadmap for Silverlight, Microsoft’s cross-platform application for delivering the next generation of media experiences."

"Microsoft® Silverlight™ is a cross-browser, cross-platform plug-in for delivering the next generation of .NET based media experiences and rich interactive applications for the Web. Silverlight offers a flexible programming model that supports AJAX, VB, C#, Python, and Ruby, and integrates with existing Web applications. Silverlight supports fast, cost-effective delivery of high-quality video to all major browsers running on the Mac OS or Windows."

If you are interested in watching that movie too, this is the link to it. Enjoy!
And there is more:
- Silverlight home page
- Silverlight Community Site
- Get started with Silverlight
- Microsoft's executives webcasts

01 May 2007

Transforming a Div into a Table


I've seen a lot of people debating about tables and divs. Some of them are saying to use tables and not divs and vice-versa.
Now, I'm showing you an example of how you can transform a div into a table.

Note that this example doesn't work in IE7 (IE7 is messing it badly), but it works in Firefox just great.

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=windows-1252">
<title>Transforming a Div into a Table</title>

<style type="text/css" media="screen">

div.table { display: table;}
div.row { display: table-row; }
div.cell { display: table-cell; width: 100px; }
div.caption { display: table-caption; caption-side: top; text-align: right; }

div.c1 { text-align: right; background-color: #eeeeee; }
div.c2 { text-align: center; }

div.TableHeaderGroup { display: table-header-group; color: Red; }
div.TableRowGroup { display: table-row-group; font-style: italic; }
div.TableFooterGroup { display: table-footer-group; color: Blue; }

</style>
</head>

<body>

<div class="table">

<div class="caption">Table caption</div>

<div class="TableHeaderGroup">
<div class="row">
<div class="cell c1">Cell 1</div>
<div class="cell c2">Cell 2</div>
</div>
</div>

<div class="TableRowGroup ">
<div class="row">
<div class="cell c1">Cell 1</div>
<div class="cell c2">Cell 2</div>
</div>
</div>

<div class="TableFooterGroup">
<div class="row">
<div class="cell c1">Cell 1</div>
<div class="cell c2">Cell 2</div>
</div>
</div>

</div>


</body>
</html>

29 April 2007

Display UTC Time

Display UTC Time


<%@ Page Language="VB" %>

<script runat="server">
Private Sub UpdateTime()

Dim culture As System.Globalization.CultureInfo =
System.Globalization.CultureInfo.GetCultureInfo(1033)
Dim currentDateTime As DateTime = DateTime.UtcNow
Me.DisplayTimeLabel.Text = String.Format(culture, "{1}", Environment.NewLine, _
currentDateTime.ToString("dddd, dd MMMM yyyy, hh:mm", culture))


End Sub

Protected Sub GetUtcTimeButton_Click(ByVal sender As Object, ByVal e As
System.EventArgs) Handles GetUtcTimeButton.Click

UpdateTime()
End Sub
</script>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>Display UTC Time</title>
</head>
<body>
<form id="AppMainForm" runat="server">
<div>
<asp:Label ID="DisplayTimeLabel" runat="server"></asp:Label>
<asp:Button ID="GetUtcTimeButton" runat="server" Text="Update" />
<br />
<br />
<asp:Label ID="ErrorLabel" runat="server" ForeColor="Red"></asp:Label>
</div>
</form>
</body>
</html>

25 April 2007

I have launched my web site


Yeap!
This is true!

Finally, I've launched my web site late last night.

I've worked a lot on this one and I really would appreciate any feedback I'll get from you!

I've tested with IE7 and FF and it worked just great, but who knows...maybe there is something that I've misspelled or maybe I have some problem with page layout on other browsers and other platforms.

This is what I got:
- OS = Windows XP Professional
- browser = IE7 and FF
- screen res = 1024 x 768


So, please take a look at http://optimizaremaster.org , and tell me what you think!

Thank you!


I've seen something interesting on youtube and I thought I'll share it here so you can amuse a little bit !



It was about 6 in the morning when I went to sleep... Now it's 12.36 PM and I feel like I've been sleeping 2 days and not just a few hours (maybe this is the reason for not having a stable relationship...!!??).

But, I have to tell you that that movie made my day!

23 April 2007

Crawling your competitor's web site

Have a quick look inside your competitor's web site.
Retrieve all the content from the head tag and analize it.


The asp.net code:


<%@ Page Language="VB" AutoEventWireup="false" ValidateRequest="false" %>

<%@ Import Namespace="System.Net" %>
<%@ Import Namespace="System.IO" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<script runat="server">
Protected Sub CrawlWebSiteButton_Click(ByVal sender As Object, ByVal e As
System.EventArgs) Handles CrawlWebSiteButton.Click

Dim connectionString As String = Me.UrlTextBox.Text

Try
Dim myRequest As System.Net.WebRequest = WebRequest.Create(connectionString)
myRequest.Credentials = CredentialCache.DefaultCredentials

Dim myProxy As System.Net.IWebProxy = New WebProxy("MyProxy", 80)
myProxy = myRequest.Proxy

Dim response As System.Net.WebResponse = myRequest.GetResponse
Dim sr As StreamReader = New StreamReader(response.GetResponseStream)

Me.allPageContentTextBox.Text = sr.ReadToEnd

Dim pageContent As String = Me.allPageContentTextBox.Text
Dim startIndex As Integer = pageContent.IndexOf("<head")

Dim endIndex As Integer = pageContent.LastIndexOf("</head>")
Me.RequestStatusLabel.Text = "Request status: " _
+ "Start index: " + startIndex.ToString() _
+ " " _
+ "End index: " + endIndex.ToString()

If startIndex > 0 AndAlso endIndex > 0 AndAlso endIndex > startIndex Then
Me.expectedResultTextBox.Text = pageContent.Substring(startIndex, endIndex -
startIndex + 7)
End If

'// Close stream
sr.Close()

Catch ex As Exception
Me.ErrorLabel.Text = "Error: " + ex.Message
End Try
End Sub
</script>

<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
<title>Header Tag Reader</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:Label ID="Label1" runat="server" Text="Input url:" Font-Names="Georgia,
Serif"
Font-Size="12pt" ForeColor="#800000"></asp:Label><br />
<asp:TextBox ID="UrlTextBox" runat="server" Font-Names="Verdana, Sans-Serif"
Font-Size="9pt"
ForeColor="#434041" Width="291px"></asp:TextBox>&nbsp;&nbsp;<asp:Button
ID="CrawlWebSiteButton" runat="server" Text="Crawl site" />
<asp:RegularExpressionValidator ID="RegularExpressionValidator1"
ControlToValidate="UrlTextBox"
runat="server" ToolTip="Input a valid URL !"
ValidationExpression="http(s)?://([\w-]+\.)+[\w-]+(/[\w-
./?%&=]*)?">*</asp:RegularExpressionValidator>
<asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server"
ControlToValidate="UrlTextBox"
ErrorMessage="This field is required!" ToolTip="This field is
required!">*</asp:RequiredFieldValidator>
</div>
<div>
<br />
<br />
<asp:Label ID="Label2" runat="server" Font-Names="Georgia, Serif"
Font-Italic="true"
Font-Size="12pt" ForeColor="#800000" Text="Head content"></asp:Label>
<br />
<asp:TextBox ID="expectedResultTextBox" runat="server" Height="269px"
TextMode="MultiLine"
Font-Names="Verdana, Sans-Serif" Font-Size="9pt" Width="724px"></asp:TextBox>
<br />
<br />
<asp:Label ID="Label3" runat="server" Font-Italic="true" Font-Names="Georgia,
Serif"
Font-Size="12pt" ForeColor="#800000" Text="Page content"></asp:Label>
<br />
<asp:TextBox ID="allPageContentTextBox" runat="server" Height="269px"
TextMode="MultiLine"
Font-Names="Verdana, Sans-Serif" Font-Size="9pt" Width="724px"></asp:TextBox>
</div>
<div>
<br />
<asp:Label ID="RequestStatusLabel" runat="server" Font-Names="Verdana,
Sans-Serif" Font-Size="10pt"
ForeColor="#800000"></asp:Label>
<br />
<br />
<asp:Label ID="ErrorLabel" ForeColor="#FF0000" runat="server"
Font-Names="Verdana, Sans-Serif"
Font-Size="10pt"></asp:Label>
</div>
</form>
</body>
</html>

21 April 2007

Make link from a span


<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>

<script type="text/javascript">
//
// Handling MouseOver & MouseOut Events

var elementId;
var StateValue = false;

function isChanged(/*As String*/ elementID, /*As Boolean*/ stateValue)
{
elementId = document.getElementById(elementID);

if (StateValue == false) // mouse is over
{
StateValue = true;
// set new values
elementId.style.color = "#FF0000";
elementId.style.cursor = "hand";
elementId.style.borderBottomStyle = "dashed";
elementId.style.borderBottomColor = "#FF0000";
elementId.style.borderBottomWidth = "1px";

}
else // mouse is out
{
StateValue = false;
// restore to initial values
elementId.style.color = "";
elementId.style.cursor = "";
elementId.style.borderBottomStyle = "";
elementId.style.borderBottomColor = "";
elementId.style.borderBottomWidth = "";
}
return StateValue;
}

</script>


<style type="text/css" media="screen">
span
{
color: #0066FF; /* Blue */
}
</style>
</head>
<body>
<span id="Span1" onmouseout="isChanged(this.id, false);"
onmouseover="isChanged(this.id, true);">Hover me!</span>
</body>
</html>

18 April 2007

FileUpload Control


Before start using this code:

  • Create a folder called UploadFiles at the root of your web site. This is where you'll upload your files.

  • Run this page in a web browser to find out what's your MaxRequestLength value. The code will be executed on page load event and the result will be displayed when the page loads completely.

  • MaxRequestLength value is the maximum size for a file to be uploaded successfuly.




<%@ Page Language="VB" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<script runat="server">

Protected Overrides Sub OnLoad(ByVal e As System.EventArgs)
MyBase.OnLoad(e)

If Not (Page.IsPostBack) Then
Dim section As New System.Web.Configuration.HttpRuntimeSection
Dim value As Integer = section.MaxRequestLength
Response.Write("MaxRequestLength: " & value)
End If

End Sub


Protected Sub FileUploader_Load(ByVal sender As Object, ByVal e As
System.EventArgs) Handles FileUploader.Load

Dim serverFilePath As String = Server.MapPath("~/UploadFiles/")
Dim fileIsGood As Boolean = False

If FileUploader.HasFile Then

Dim fileExtension As String =
System.IO.Path.GetExtension(FileUploader.FileName).ToLower()
Dim defaultExtensions As String() = {".jpg", ".jpeg", ".png", ".gif"}

For i As Integer = 0 To defaultExtensions.Length - 1
If fileExtension = defaultExtensions(i) Then
fileIsGood = True
End If
Next

If fileIsGood Then
Try
FileUploader.PostedFile.SaveAs(serverFilePath & FileUploader.FileName)
Me.ErrorLabelFileUpload.Text = "Your image was uploaded!"
'// Optional: display the path and the file name of the uploaded file
Me.FileNameLabel.Text = serverFilePath & FileUploader.FileName

Catch ex As Exception
Me.ErrorLabelFileUpload.Text = "Your image could not be uploaded."
End Try

Else
Me.ErrorLabelFileUpload.Text = "Please select a valid image file!"
End If
End If
End Sub
</script>

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title>Upload files to server</title>
</head>
<body>
<form id="AppMainForm" runat="server">
<div>
</div>
<div>
<asp:FileUpload ID="FileUploader" runat="server" Width="430px" />
<br />
<asp:Button ID="FileUploadButton" runat="server" Text="Upload" />
<br />
<br />
<asp:Label ID="ErrorLabelFileUpload" ForeColor="Red" runat="server"></asp:Label>
<br />
<br />
<asp:Label ID="FileNameLabel" runat="server" ForeColor="Black"></asp:Label>
</div>
</form>
</body>
</html>

Browser Redirects

Implementing browser redirects




Using meta refresh:


<meta http-equiv="refresh" content="0; url=http://jasp-costin.blogspot.com">


Using JavaScript:


<script type="text/javascript">
<!--
function NavigateAway()
{
     window.location.href = "http://jasp-costin.blogspot.com";
}
//-->
</script>
<body onload="NavigateAway();">
.....
</body>


Using ASP.NET


Protected Overrides Sub OnLoad(ByVal e As System.EventArgs)
MyBase.OnLoad(e)
     Response.Status = "301 Moved Permanently"
     Response.AddHeader("Location", "http://jasp-costin.blogspot.com")
     Response.End()
End Sub

16 April 2007

View last modified date


<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>

<script type="text/javascript">
//
//
// VIEW LAST MODIFIED DATE

function getLastDate(/*STRING*/ id)
{
var elementId = document.getElementById(id);

var m_lastDate = document.lastModified;

elementId.innerHTML = m_lastDate;
}
</script>


</head>

<body onload="getLastDate('Span1');">

<span id="Span1"></span>

</body>

</html>

Set As Home Page

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>

<script type="text/javascript">
//
// MAKE HOME-PAGE
//
function makeHomePage(/*STRING*/ elementId)
{
TheLink = document.getElementById(elementId);
TheLink.style.behavior='url(#default#homepage)';
TheLink.setHomePage('http://jasp-costin.blogspot.com');
}
</script>


</head>

<body>

<span id="MakeHomePage_Span" onclick="makeHomePage(this.id);">Set as home
page</span>

</body>
</html>

Open Popup Window


<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>

<head>

<script type="text/javascript">
<!--
function openWindow()
{
// The complete url to the html page you want to open
var streamUrl = "http://jasp-costin.blogspot.com";
var popUpWindow;

// For this popup title: use only one word (e.g "Title").
// Do not split your title like this (e.g "My Title") or you'll get an exception
var windowTitle = "EasyWebDevelopment";

// Manage your page features
// 0 = false; 1 = true
var features = "width=520, height=228, menubar=1, toolbar=0, location=0,
status=1, scrollbars=1, resizable=1";

popUpWindow = window.open(streamUrl, windowTitle, features);
popUpWindow.focus();
}
//-->
</script>

</head>

<body>
<span id="Span1" onclick="openWindow();" style="cursor: hand;">Open pop-up
window</span>
</body>
</html>

Display Current Date


<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>

<script type="text/javascript">
//
// DISPLAY DATE
//
function GetCurrentDate()
{
var months = new Array(13);
months[1]= "January";
months[2]= "February";
months[3]= "March";
months[4]= "April";
months[5]= "May";
months[6]= "June";
months[7]= "July";
months[8]= "August";
months[9]= "September";
months[10]= "October";
months[11]= "November";
months[12]= "December";

var time = new Date();
var lmonth = months[time.getMonth() + 1];
var date = time.getDate();
var year = time.getYear();

if (year < 2000)
year = year + 1900;
document.write(lmonth + " " + date + " " + year);
}

</script>


</head>
<body>

<span>
<script type="text/javascript">GetCurrentDate();</script>
</span>

</body>
</html>

Add Page To Favorites


This script will help you to add a given page to favorites.
It's quite small, simple and easy to understand.


<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>

<script type="text/javascript">
//
// ADD THIS PAGE TO FAVORITES
//
function addPageToFav(/*STRING*/ title, /*STRING*/ url )
{
if (document.all)
window.external.AddFavorite(url, title);
else if (window.sidebar)
window.sidebar.addPanel(title, url, "");
}
</script>


</head>

<body>

<span id="AddToFav_Span"
onclick="addPageToFav('EasyWebDevelopment','http://jasp-costin.blogspot.com')">Add
to favorites</span>

</body>
</html>

DropDown navigation menu


The code for aspx page

<%@ Page Language="VB" %>
<script runat="server">
Protected Sub SelectionDropDownList_SelectedIndexChanged(ByVal sender As Object,
ByVal e As System.EventArgs) _
Handles SelectionDropDownList.SelectedIndexChanged

If Not (SelectionDropDownList.SelectedIndex = 0) Then

Page.Response.Redirect(Me.SelectionDropDownList.SelectedItem.Value)

End If
End Sub
</script>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>Untitled Page</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:DropDownList ID="SelectionDropDownList" runat="server" AutoPostBack="True">
<asp:ListItem Selected="True">--Select Options--</asp:ListItem>
<asp:ListItem Value="http://www.sitepoint.com">Site point</asp:ListItem>
<asp:ListItem Value="http://www.google.com">Google</asp:ListItem>
<asp:ListItem Value="http://www.yahoo.com">Yahoo</asp:ListItem>
<asp:ListItem Value="http://www.live.com">Live Search</asp:ListItem>
</asp:DropDownList>
</div>
</form>
</body>
</html>


The HTML page

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>

<head>
<meta http-equiv="Content-Type" content="text/html; charset=windows-1252">
<title>New Page 1</title>
<script type="text/javascript">
<!--
function NavigateUp(/*As String*/ elementID)
{
var theSelector = document.getElementById(elementID);
var theIndex = theSelector.selectedIndex;
var theUrl = theSelector.options[theIndex].value;

window.location.href = theUrl;

return true;
}
//-->
</script>
</head>

<body>
<select SelectedIndex="0" id="SelectionDropDownList"
onchange="NavigateUp(this.id);">
<option value="#">--Select Options--</option>
<option value="http://www.sitepoint.com">Site point</option>
<option value="http://www.google.com">Google</option>
<option value="http://www.yahoo.com">Yahoo</option>
<option value="http://www.live.com">Live Search</option>

</select>
</body>
</html>

13 April 2007

How to send an e-mail using ASP.NET 2.0


This page I use to send e-mails and offers you the possibility to attach a file to your message and also you can specify how to send it (as HTML or as plain text)
==================================================

1 <%@ Page Language="VB" ValidateRequest="false" %>


2


3 <%@ Import Namespace="System.Net.Mail" %>


4 <%@ Import Namespace="System.Net.Mail.SmtpClient" %>


5 <%@ Import Namespace="System.IO" %>


6 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">


7


8 <script runat="server">


9 Private Sub ClearForm()


10 Me.SenderTextBox.Text = ""


11 Me.SubjectTextBox.Text = ""


12 Me.MessageTextBox.Text = ""


13 End Sub


14


15 Protected Overrides Sub OnLoadComplete(ByVal e As System.EventArgs)


16 MyBase.OnLoadComplete(e)


17 '// Clear the form


18 ClearForm()


19 End Sub


20


21 Protected Sub sendMessageButton_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles SendMessageButton.Click


22


23 '// Grab the data for your message


24 Dim _theSender As String = Me.SenderTextBox.Text


25


26 Dim _theReceiver As String = "" '// "your e-mail address here" '// e.g. someone@example.com


27 Dim _theSubject As String = Me.SubjectTextBox.Text


28 Dim _theMessage As String = Me.MessageTextBox.Text


29


30 '// Compose the message


31 Dim theMessage As New MailMessage(_theSender, _theReceiver, _theSubject, _theMessage)


32 theMessage.Priority = MailPriority.Normal


33


34 '// This should be your internet provider mail server address


35 Dim theHost As New SmtpClient("")


36


37 '// Create the attachment


38 Dim attachedFile As Attachment = New Attachment(Me.AttachmentFileUpload.PostedFile.InputStream, Me.AttachmentFileUpload.FileName)


39


40 Try


41 If (Me.SendAsHtmlRadioButton.Checked = True) Then


42 Try


43 '// Verify if file attached


44 If Not (String.IsNullOrEmpty(Me.AttachmentFileUpload.FileName) OrElse (Me.AttachmentFileUpload.PostedFile Is Nothing)) Then


45 '// Attach the file


46 theMessage.Attachments.Add(attachedFile)


47 Else


48 '// There is no need to treat this error here.


49 '// the RequiredFieldValidator will do the job


50 End If


51


52 '// Get your message content and declare it as HTML content


53 theMessage.Body = Me.MessageTextBox.Text


54 theMessage.IsBodyHtml = True


55


56 '// Send the message


57 theHost.Send(theMessage)


58


59 ClearForm()


60 '// Show success message


61 Me.ErrorMessageLabel.Text = "Success: The message was sent"


62


63 Catch ex As Exception


64 '// Show error message


65 Me.ErrorMessageLabel.Text = "Error: The message was not sent"


66


67 End Try


68


69 ElseIf (Me.SendAsTextRadioButton.Checked = True) Then


70 Try


71 '// Verify if file attached


72 If Not (String.IsNullOrEmpty(Me.AttachmentFileUpload.FileName) OrElse (Me.AttachmentFileUpload.PostedFile Is Nothing)) Then


73 '// Attach the file


74 theMessage.Attachments.Add(attachedFile)


75 Else


76 '// There is no need to treat this error here.


77 '// the RequiredFieldValidator will do the job


78 End If


79


80 '// Get your message content and declare it as plain Text content


81 theMessage.Body = Me.MessageTextBox.Text


82 theMessage.IsBodyHtml = False


83


84 '// Send the message


85 theHost.Send(theMessage)


86


87 ClearForm()


88 '// Show success message


89 Me.ErrorMessageLabel.Text = "Success: The message was sent"


90


91 Catch ex As Exception


92 '// Show error message


93 Me.ErrorMessageLabel.Text = "Error: The message was not sent"


94 End Try


95 End If


96


97 Catch ex As Exception


98 '// Show error message


99 Me.ErrorMessageLabel.Text = "Error: The message was not sent"


100


101 End Try


102


103 End Sub


104


105 </script>


106


107 <html xmlns="http://www.w3.org/1999/xhtml">


108 <head id="Head1" runat="server">


109 <title>How to send an e-mail message</title>


110 <style type="text/css" media="screen">


111


112 body


113 {


114 font-family: Verdana, Sans-Serif;


115 font-size: 9pt;


116 color: #000000;


117 text-align: center;


118 vertical-align: top;


119 }


120 .ctSpacer


121 {


122 height: 10px;


123 }


124 FORM#AppMailForm


125 {


126 width: 100%;


127 height: auto;


128 }


129 div.ctWrapper


130 {


131 width: 700px;


132 height: auto;


133 text-align: center;


134 vertical-align: top;


135 }


136 TD#ContactFormContainerCell


137 {


138 width: 100%;


139 height: auto;


140 text-align: center;


141 vertical-align: top;


142 }


143 table.ctTableContact


144 {


145 width: 100%;


146 height: auto;


147 text-align: left;


148 vertical-align: top;


149 }


150 TD.ctPageTitle


151 {


152 width: 100%;


153 height: 35px;


154 text-align: left;


155 vertical-align: middle;


156 padding-left: 15px;


157 background-color: #eeeeee;


158 border-bottom: solid 2px #cccccc;


159 }


160 .ctPageTitleLabel


161 {


162 font-family: Georgia, Serif;


163 font-size: 10pt;


164 color: #900000;


165 font-weight: bold;


166 }


167 .TextCell


168 {


169 width: 100%;


170 height: 20px;


171 text-align: left;


172 vertical-align: middle;


173 }


174 .LabelControls


175 {


176 font: 9pt Verdana, Sans-Serif;


177 color: #434041;


178 }


179 .InputCell


180 {


181 width: 100%;


182 height: 25px;


183 text-align: left;


184 vertical-align: middle;


185 }


186 .InputCell input


187 {


188 text-align: left;


189 vertical-align: middle;


190 color: #434041;


191 }


192 .validatorHand


193 {


194 cursor: hand;


195 }


196 td.Note span


197 {


198 font-family: Verdana, Sans-Serif;


199 font-size: 11pt;


200 font-weight: bold;


201 color: #000000;


202 }


203 .infoMessage


204 {


205 font: 8pt Verdana, Sans-Serif;


206 color: #434041;


207 }


208 input.SendMessageButton


209 {


210 text-align: center;


211 vertical-align: middle;


212 }


213 #AllControlsValidationSummary


214 {


215 width: 99%;


216 height: auto;


217 text-align: left;


218 vertical-align: top;


219 padding-left: 5px;


220 padding-top: 5px;


221 }


222 </style>


223 </head>


224 <body>


225 <form id="AppMailForm" runat="server" method="post" enctype="multipart/form-data">


226 <div class="ctWrapper">


227 <table class="ctTableContact" cellpadding="0" cellspacing="0">


228 <thead>


229 <tr id="MAIL_HEADER">


230 <td class="ctPageTitle">


231 <asp:Label ID="PageTitleLabel" runat="server" CssClass="ctPageTitleLabel">Send Mail Message</asp:Label>


232 </td>


233 </tr>


234 <tr>


235 <td class="ctSpacer">


236 </td>


237 </tr>


238 </thead>


239 <tbody id="MAIL_CONTENT">


240 <tr>


241 <td id="ContactFormContainerCell">


242 <table class="ctTableContact" cellpadding="2" cellspacing="2">


243 <tbody>


244 <tr>


245 <td id="Td1" class="TextCell">


246 <asp:Label ID="FromLabel" runat="server" Text="Sender:" CssClass="LabelControls"></asp:Label>


247 <asp:RequiredFieldValidator ID="RequiredFieldValidatorSenderTextBox" runat="server"


248 ControlToValidate="SenderTextBox" CssClass="validatorHand" ErrorMessage='You must provide an e-mail address! This field is required.'


249 Font-Names="Verdana" Font-Size="12pt" ForeColor="#FF0000" ToolTip='You must provide an e-mail address!'>*</asp:RequiredFieldValidator></td>


250 </tr>


251 <tr>


252 <td id="Td2" class="InputCell">


253 <asp:TextBox ID="SenderTextBox" runat="server" Width="200px"></asp:TextBox>


254 <asp:RegularExpressionValidator ID="RegularExpressionValidatorSenderTextBox" runat="server"


255 ControlToValidate="SenderTextBox" ErrorMessage='Your e-mail address is not in the right format!'


256 Font-Names="Verdana" Font-Size="12pt" ForeColor="#ff0000" ValidationExpression="\w+([-+.']\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*">*</asp:RegularExpressionValidator></td>


257 </tr>


258 <tr>


259 <td id="Td5" class="TextCell">


260 <asp:Label ID="SubjectLabel" runat="server" CssClass="LabelControls" Text="Subject:"></asp:Label>


261 <asp:RequiredFieldValidator ID="RequiredFieldValidatorSubjectTextBox" runat="server"


262 ControlToValidate="SubjectTextBox" CssClass="validatorHand" ErrorMessage='You must provide a subject to your message! This field is required.'


263 Font-Names="Verdana" Font-Size="12pt" ForeColor="#ff0000" ToolTip='You must provide a subject to your message!'>*</asp:RequiredFieldValidator></td>


264 </tr>


265 <tr>


266 <td id="Td6" class="InputCell">


267 <asp:TextBox ID="SubjectTextBox" runat="server" Width="300px"></asp:TextBox>


268 </td>


269 </tr>


270 <tr>


271 <td id="Td7" class="TextCell">


272 <asp:Label ID="MesssageLabel" runat="server" CssClass="LabelControls" Text="Message:"></asp:Label>


273 <asp:RequiredFieldValidator ID="RequiredFieldValidatorMessageTextBox" runat="server"


274 ControlToValidate="MessageTextBox" CssClass="validatorHand" ErrorMessage='You cannot send a blank message! This field is required.'


275 Font-Names="Verdana" Font-Size="12pt" ForeColor="#ff0000" ToolTip='You cannot send a blank message!'>*</asp:RequiredFieldValidator></td>


276 </tr>


277 <tr>


278 <td id="Td8" class="InputCell">


279 <asp:TextBox ID="MessageTextBox" runat="server" Height="123px" TextMode="MultiLine"


280 Width="458px" MaxLength="500"></asp:TextBox>


281 <br />


282 <asp:Label ID="InfoLabel" runat="server" CssClass="infoMessage">500 chars max</asp:Label>


283 </td>


284 </tr>


285 <tr>


286 <td class="InputCell">


287 <asp:RadioButton ID="SendAsHtmlRadioButton" runat="server" Checked="true" Text="Send as HTML"


288 GroupName="MailingOptions" />


289 <asp:RadioButton ID="SendAsTextRadioButton" runat="server" Checked="false" Text="Send as Text"


290 GroupName="MailingOptions" /></td>


291 </tr>


292 <tr>


293 <td id="AttachmentFileUploadCell" runat="server" class="InputCell">


294 <asp:FileUpload ID="AttachmentFileUpload" runat="server" Width="458px" />


295 <asp:RequiredFieldValidator ID="UploaderRequiredFieldValidator" runat="server" ControlToValidate="AttachmentFileUpload"


296 CssClass="validatorHand" ErrorMessage="No file was attached to your message. This field is required."


297 ToolTip="This field is required.">*</asp:RequiredFieldValidator></td>


298 </tr>


299 <tr>


300 <td class="InputCell">


301 <asp:Label ID="ErrorMessageLabel" runat="server" ForeColor="red"></asp:Label>


302 </td>


303 </tr>


304 <tr>


305 <td id="Td9" class="InputCell">


306 <asp:Button ID="SendMessageButton" CssClass="SendMessageButton" runat="server" Text="Send" />


307 </td>


308 </tr>


309 </tbody>


310 <tfoot>


311 <tr>


312 <td class="CaptionContentCell">


313 <asp:ValidationSummary ID="AllControlsValidationSummary" runat="server" BackColor="#eeeeee"


314 BorderColor="#cccCCC" BorderStyle="Solid" BorderWidth="1px" Font-Names="Verdana, Sans-Serif"


315 Font-Size="8pt" ForeColor="#ff0000" HeaderText="Fix the following errors:" />


316 </td>


317 </tr>


318 </tfoot>


319 </table>


320 </td>


321 </tr>


322 </tbody>


323 </table>


324 </div>


325 </form>


326 </body>


327 </html>