Friday, September 23, 2011

Top of the Page.

<p align="center"><a href="#top"><img src="images/top_arrow.png" border="0" alt="top arrow" title="Go to the top of the page"/></a></p>
This code works in IE and does not work in other browsers. I found that I have to add <div id="top"> </div> on a top of the page.
After I added it works for all browsers. Enjoy world of browsers!

Thursday, September 15, 2011

Send Email via SMTP using VB.NET

Create an aspx-file and enter the code for form:
<div align="left" id="dataform">
<table align="left" cellpadding="5" cellspacing="0" border="0" width="100%" bgcolor="#f2f2f2">
<tr>
<td colspan="2" align="center"><h3>Data Request Form</h3></td>
</tr>
<tr>
<td align="center" colspan="2"><asp:Label ID="FinalMessage" runat="server" Text=""></asp:Label></td>
</tr>
<tr>
<td align="right" width="250" valign="top"><asp:Label ID="Lbl_fname" runat="server" Text="Fist Name"></asp:Label></td>
<td align="left" valign="top">
<asp:TextBox ID="txt_fname" runat="server"></asp:TextBox>
<asp:RequiredFieldValidator runat="server" id="reqFName"
controltovalidate="txt_fname" style="color:Red;" >*</asp:RequiredFieldValidator>
</td>
</tr>
<tr>
<td align="right" width="250" valign="top"><asp:Label ID="Lbl_lname" runat="server" Text="Last Name"></asp:Label></td>
<td align="left" valign="top">
<asp:TextBox ID="txt_lname" runat="server"></asp:TextBox>
<asp:RequiredFieldValidator runat="server" id="reqLName"
controltovalidate="txt_lname" style="color:Red;">*</asp:RequiredFieldValidator>
</td>
</tr>
<tr>
<td align="right" width="250" valign="top"><asp:Label ID="Lbl_email" runat="server" Text="Email"></asp:Label></td>
<td align="left" valign="top">
<asp:TextBox ID="txt_email" runat="server"></asp:TextBox>
<asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server"
ControlToValidate="txt_email" style="color:Red;">*</asp:RequiredFieldValidator>
<asp:RegularExpressionValidator id="RegularExpressionValidator1" runat="server" ControlToValidate="txt_email"
ErrorMessage="You must enter a valid email address" style="color:Red;"
ValidationExpression="\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*">
</asp:RegularExpressionValidator>
</td>
</tr>
<tr>
<td align="right" width="250" valign="top"><asp:Label ID="Lbl_org" runat="server" Text="Organization"></asp:Label></td>
<td align="left" valign="top">
<asp:TextBox ID="txt_org" runat="server"></asp:TextBox>
<asp:RequiredFieldValidator runat="server" id="reqOrg"
controltovalidate="txt_org" style="color:Red;">*</asp:RequiredFieldValidator>
</td>
</tr>
<tr>
<td align="right" width="250" valign="top"><asp:Label ID="Lbl_phone" runat="server" Text="Phone"></asp:Label></td>
<td align="left" valign="top">
<asp:TextBox ID="txt_phone" runat="server"></asp:TextBox>
</td>
</tr>
<tr>
<td align="right" width="250" valign="top"><asp:Label ID="Lbl_fax" runat="server" Text="Fax"></asp:Label></td>
<td align="left" valign="top">
<asp:TextBox ID="txt_fax" runat="server"></asp:TextBox>
</td>
</tr>
<tr><td colspan="2" height="30px"></td></tr>
<tr>
<td align="right" width="250" valign="top"><asp:Label ID="Lbl_data" runat="server" Text="Data Requested"></asp:Label></td>
<td align="left" valign="top">
<asp:TextBox ID="txt_data" runat="server" TextMode="multiline" Rows="10" Columns="45"></asp:TextBox>
<asp:RequiredFieldValidator runat="server" id="reqdata"
controltovalidate="txt_data" style="color:Red;">*</asp:RequiredFieldValidator>
</td>
</tr>
<tr>
<td width="250"> </td>
<td align="left"><asp:Button ID="Send" runat="server" Text="Send" type="Submit"/>
<asp:Button ID="Reset" runat="server" Text="Reset" OnClientClick="this.form.reset();return false;" /></td>
</tr>
<tr>
<td height="20" colspan="2"> </td>
</tr>
</table>
</div>
Open the corresponding aspx.vb-file and enter "Imports System.Net.Mail" on a top. Enter the code below:Protected Sub Send_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Send.Click
'original code http://msdn.microsoft.com/en-us/library/system.net.mail.mailmessage.from.aspx

Dim email, name, org, phone, fax, data As String
email = txt_email.Text.Trim()
name = txt_fname.Text.Trim() + " " + txt_lname.Text.Trim()
org = txt_org.Text.Trim()
phone = txt_phone.Text.Trim()
fax = txt_fax.Text.Trim()
data = txt_data.Text.Trim()

Dim [from] As New MailAddress(email, name)
Dim [to] As New MailAddress("astaroseletskaya@cdrg.org", "Alla Staroseletskaya")
Dim message As New MailMessage([from], [to])
message.Subject = "Data Request"
message.Body = "This message was sent by" + name + " from email address " + email + ". Organization: " + org + " Phone: " + phone + " Fax: " + fax + " Request: " + data

Dim smtpClient As System.Net.Mail.SmtpClient = New System.Net.Mail.SmtpClient()
Try
smtpClient.Send(message)
FinalMessage.Text = "Message Sent"
Catch ex As Exception
FinalMessage.Text = ex.ToString()
End Try
End Sub

Tuesday, September 13, 2011

ListView with HyperLink column


Here's my first try to work with a ListView. Before I had never used this control, but in my situation it became very handy. The results on my picture.
Here's a source code

<asp:ListView runat="server" ID="ListView1"
DataSourceID="SqlDataSource1">
<LayoutTemplate>
<table runat="server" id="table1" cellpadding="0" cellspacing="0" border="0">
<tr runat="server" id="itemPlaceholder" ></tr>
</table>
</LayoutTemplate>
<ItemTemplate>
<tr id="Tr1" runat="server">
<td id="Td1" runat="server" valign="top">
<asp:Label ID="Year" runat="server" Text='<%#Eval("year") %>'/>
</td>
<td width="30px"> </td>
<td id="Td2" runat="server">
<asp:Label ID="Title" runat="server"
Text='<%#Eval("title") %>' style="font-weight:bold;" />
</td>
</tr>
<tr id="Tr2" runat="server">
<td> </td>
<td width="30px"> </td>
<td id="Td3" runat="server">
<asp:Label ID="Author" runat="server"
Text='<%#Eval("author") %>'/>
</td>
</tr>
<tr id="Tr3" runat="server">
<td> </td>
<td width="30px"> </td>
<td id="Td4" runat="server">
<asp:Label ID="Journal" runat="server"
Text='<%#Eval("journal") %>'/>
</td>
</tr>
<tr id="Tr4" runat="server">
<td> </td>
<td width="30px"> </td>
<td id="Td5" runat="server">
<asp:HyperLink ID="Link" Target="_blank"
NavigateUrl='<%# Eval("link") %>'
runat="server">Link to the article</asp:HyperLink>
</td>
</tr>
</ItemTemplate>
</asp:ListView>

Most interesting part is a HyperLink column. This feature became very useful for my project and works just fine.

Again Section 508

Today I concentrate on section 508. There are a lot of new and interesting ideas to work on. I'm surprised, how difficult is to satisfy gov requirements. From another side, it's quite good that government takes care of people with vision problems. It's great that more and more people can access Internet and be part of Web community. American government creates a very detailed document to follow. Now I do have more understanding of section 508.

Wednesday, September 7, 2011

CSS maker

Here's a very useful site for css. I hope everyone will enjoy site capabilities and implements in own projects. Enjoy!