Asp-Net Components : Example 1
- Add Link Form Demo (VB.net)
- Your calendar (C#)
- Database query form Demo (VB.net)
- Guest Book Demo (C#)
- issue reporter Demo (C#)
- Popup menu Demo (C#)
- Quiz form Demo (VB.net)
- Survey form Demo (VB.net)
- Tip of the Day Demo (VB.net)
- What is new form (VB.net)
- Use Image as the indicator for validation (C#)
- Simplest Progress Bar (VB.net)
- Phone Book Demo (VB.net)
- Use Multiview to handle form submission (C#)
- Login form Demo (VB.net)
- Help wizard form (VB.net)
- Contact Page (VB.net
- Address form Demo (VB.net)
Add Link Form Demo (VB.net)
<%--
Code revised from
ASP.NET Tips & Techniques (Paperback)
by Greg Buczek
# Publisher: McGraw-Hill/Osborne Media; 1st edition (May 21, 2002)
# Language: English
# ISBN: 0072225149
--%>
<%@ Page Language=VB Debug=true %>
<%@ Import Namespace="System.Data" %>
<%@ Import Namespace="System.Data.OLEDB" %>
<script runat=server>
Sub Page_Load(ByVal Sender as Object, ByVal E as EventArgs)
Dim DBConn as OleDbConnection
Dim DBCommand As OleDbDataAdapter
Dim DSPageData as New DataSet
DBConn = New OleDbConnection( _
"PROVIDER=Microsoft.Jet.OLEDB.4.0;" _
& "DATA SOURCE=" _
& Server.MapPath _
("LinksDB.mdb;"))
DBCommand = New OleDbDataAdapter _
("Select '<A HREF=""' & TheLink & '"">' " _
& "& LinkTitle & '</A>' as [Link], " _
& "LinkDescription as [Description] From Links " _
& "Order By LinkTitle", DBConn)
DBCommand.Fill(DSPageData, _
"Links")
dgLinks.DataSource = _
DSPageData.Tables("Links").DefaultView
dgLinks.DataBind()
End Sub
</SCRIPT>
<HTML>
<HEAD>
<TITLE>Links Page</TITLE>
</HEAD>
<Body LEFTMARGIN="40">
<form runat="server">
<BR><BR>
<asp:label
id="lblMessage1"
font-size="12pt"
font-bold="True"
font-name="Lucida Console"
text="Current Links List"
runat="server"
/>
<BR><BR>
<asp:datagrid
id="dgLinks"
runat="server"
autogeneratecolumns="True"
/>
<BR><BR>
<A HREF="./addlink.aspx">Add a Link</A>
</form>
</BODY>
</HTML>
<%-- File: addLink.aspx
<%@ Page Language=VB Debug=true %>
<%@ Import Namespace="System.Data" %>
<%@ Import Namespace="System.Data.OLEDB" %>
<script runat=server>
Sub SubmitBtn_Click(Sender As Object, E As EventArgs)
Dim DBConn as OleDbConnection
Dim DBAdd As New OleDbCommand
DBConn = New OleDbConnection( _
"PROVIDER=Microsoft.Jet.OLEDB.4.0;" _
& "DATA SOURCE=" _
& Server.MapPath _
("LinksDB.mdb;"))
DBAdd.CommandText = "Insert Into Links " _
& "(LinkTitle, TheLink, LinkDescription) " _
& "values (" _
& "'" & Replace(txtLinkTitle.Text, "'", "''") _
& "', " _
& "'" & Replace(txtTheLink.Text, "'", "''") _
& "', " _
& "'" & Replace(txtLinkDescription.Text, "'", "''") _
& "')"
DBAdd.Connection = DBConn
DBAdd.Connection.Open
DBAdd.ExecuteNonQuery()
Response.Redirect("./links.aspx")
End Sub
</SCRIPT>
<HTML>
<HEAD>
<TITLE>Add Link</TITLE>
</HEAD>
<form runat="server">
<asp:Label
id="lblMessage"
Font-Size="12pt"
Font-Name="Tahoma"
runat="server"
Text="Complete each field to submit your link."
/>
<P></P><Font Face="Tahoma">Link Title:</Font><BR>
<asp:textbox
id="txtLinkTitle"
columns="25"
maxlength="50"
runat=server
/>
<P></P><Font Face="Tahoma">Link Address:</Font><BR>
<asp:textbox
id="txtTheLink"
columns="25"
maxlength="100"
runat=server
/>
<P></P><Font Face="Tahoma">Link Description:</Font><BR>
<asp:textbox
id="txtLinkDescription"
columns="25"
maxlength="255"
runat=server
/>
<BR><BR>
<asp:button
id="butOK"
text=" OK "
OnClick="SubmitBtn_Click"
runat="server"
/>
</form>
</BODY>
</HTML>
--%>Your calendar (C#)
<%-- Beginning ASP.NET 1.0 with C# (Paperback) by David Sussman, Chris Ullman, Juan T. Llibre, John Kauffman, Ollie Cornes, Ajoy Krishnamoorthy, Srinivasa Sivakumar, Chris Goode, Neil Raybould, Christopher Miller, Rob Birdwell, Matt Butler, Gary Johnson # Publisher: Wrox Press; 1st edition (June 2002) # Language: English # ISBN: 1861007345 --%> <%@ Page Language="c#" %> <%@ Import Namespace="System.Data"%> <%@ Import Namespace="System.IO" %> <%@ Import Namespace="System.Globalization" %> <html> <head> <script language="c#" runat="server"> protected void Page_Load(object sender, EventArgs e) { if (!(IsPostBack)) { ShowDailyEvents(); } } public void MyCalendar_SelectionChanged(object sender, EventArgs e) { ShowDailyEvents(); } protected DataSet LoadMyCalendarData() { string sourceXml = Server.MapPath("MyCalendar.xml"); if (!(File.Exists(sourceXml))) { return null; } DataSet cachedDataSet = (DataSet)Session["MyCalendarData"]; if (cachedDataSet != null) { return cachedDataSet; } DataSet dataSet = new DataSet(); try { dataSet.ReadXml(sourceXml); Session["MyCalendarData"] = dataSet; } catch (Exception e) { SelectedDate.Text = e.Message; dataSet = null; } return dataSet; } protected void MyCalendar_DayRender(object sender, DayRenderEventArgs e) { if (e.Day.IsOtherMonth) { e.Cell.BackColor=System.Drawing.Color.FromName("Gainsboro"); } else { if (e.Day.IsWeekend) { e.Cell.BackColor=System.Drawing.Color.FromName("PaleGoldenrod"); } else { e.Cell.BackColor=System.Drawing.Color.FromName("LightGoldenrodYellow"); } } DataSet dataSet = LoadMyCalendarData(); if (dataSet == null) { return; } foreach (DataRow zRow in dataSet.Tables[0].Rows) { DateTime compareDate = GetSafeDate(zRow["EventDate"].ToString()); if (compareDate == e.Day.Date) { // Event matches date criteria ?display it... MyCalendarEventData myEventData = new MyCalendarEventData(); myEventData.ShortDesc = zRow["ShortDesc"].ToString(); myEventData.DetailDesc = zRow["DetailDesc"].ToString(); myEventData.StartTime = zRow["StartTime"].ToString(); myEventData.EndTime = zRow["EndTime"].ToString(); Label dailyEventLabel = new Label(); dailyEventLabel.Text = "<br />" + myEventData.ShortDesc; e.Cell.Controls.Add(dailyEventLabel); } } } protected void ShowDailyEvents() { DateTime d = MyCalendar.SelectedDate; DataSet dataSet = LoadMyCalendarData(); if (dataSet == null) { return; } ArrayList aEvents = new ArrayList(); foreach (DataRow zRow in dataSet.Tables[0].Rows) { DateTime compareDate = GetSafeDate(zRow["EventDate"].ToString()); if (compareDate == d) { // Event matches date criteria ?display it... MyCalendarEventData myEventData = new MyCalendarEventData(); myEventData.EventDate = d; myEventData.ShortDesc = zRow["ShortDesc"].ToString(); myEventData.DetailDesc = zRow["DetailDesc"].ToString(); myEventData.StartTime = zRow["StartTime"].ToString(); myEventData.EndTime = zRow["EndTime"].ToString(); aEvents.Add(myEventData); } } // Bind to the Repeater control... DailyEventDetailRepeater.DataSource = aEvents; DailyEventDetailRepeater.DataBind(); if (aEvents.Count > 0) { DailyDetailsPanel.Visible = true; SelectedDate.Text = "Events For " + d.ToLongDateString(); } else { DailyDetailsPanel.Visible = false; SelectedDate.Text = "No Events Scheduled For " + d.ToLongDateString(); } } private DateTime GetSafeDate(string proposedDate) { // Returns a non-null DateTime even if proposed date can't be parsed DateTime safeDate; try { safeDate = DateTime.Parse(proposedDate, DateTimeFormatInfo.InvariantInfo); } catch (Exception e) { Response.Write("<!-- Failed to parse date: " + e.Message + " -->"); safeDate = DateTime.MinValue; } return safeDate; } public class MyCalendarEventData { private string m_ShortDesc; private string m_DetailDesc; private DateTime m_EventDate; private string m_StartTime; private string m_EndTime; public string ShortDesc { get { return m_ShortDesc; } set { m_ShortDesc = value; } } public string DetailDesc { get { return m_DetailDesc; } set { m_DetailDesc = value; } } public DateTime EventDate { get { return m_EventDate; } set { m_EventDate = value; } } public string StartTime { get { return m_StartTime; } set { m_StartTime = value; } } public string EndTime { get { return m_EndTime; } set { m_EndTime = value; } } } </script> </head> <body> <h1>My Calendar</h1> <form id="MyCalendarForm" method="post" runat="server"> <p align="center"> <asp:Calendar id="MyCalendar" runat="server" SelectedDate="2002/07/17" VisibleDate="2002/07/01" FirstDayOfWeek="Monday" DayNameFormat="Full" ShowDayHeader="True" ShowGridLines="True" ShowNextPrevMonth="True" ShowTitle="True" nextprevstyle-backcolor="DodgerBlue" nextprevstyle-forecolor="White" nextprevstyle-font-bold="True" nextprevstyle-font-size="Large" TitleFormat="MonthYear" TitleStyle-BackColor="DodgerBlue" TitleStyle-ForeColor="White" TitleStyle-Font-Size="Large" TitleStyle-Font-Bold="True" dayheaderstyle-backcolor="DodgerBlue" dayheaderstyle-forecolor="White" daystyle-horizontalalign="Left" daystyle-verticalalign="Top" daystyle-font-size="Small" SelectedDayStyle-Font-Bold="True" selecteddaystyle-horizontalalign="Left" selecteddaystyle-verticalalign="Top" selecteddaystyle-font-size="Small" selecteddaystyle-forecolor="Red" TodayDayStyle-HorizontalAlign="Left" TodayDayStyle-VerticalAlign="Top" todaydaystyle-backcolor="White" OnDayRender="MyCalendar_DayRender" OnSelectionChanged="MyCalendar_SelectionChanged"> </asp:Calendar> </p> <p align="center"> <asp:label id="SelectedDate" runat="server" font-size="Large" /> </p> <asp:panel id="DailyDetailsPanel" runat="server"> <asp:Repeater id="DailyEventDetailRepeater" runat="server"> <HeaderTemplate> <p align="center"> <table border="1" width="100%"> <table style="color:Black;border collapse:collapse;"> <tr style="color:White;background-color:DodgerBlue; font-weight:bold;"> <td><b>Event</b></td> <td><b>Description</b></td> <td><b>Start Time</b></td> <td><b>End Time</b></td> </tr> </HeaderTemplate> <ItemTemplate> <tr style="background-color:White;"> <td><%# DataBinder.Eval(Container.DataItem, "ShortDesc") %></td> <td><%# DataBinder.Eval(Container.DataItem, "DetailDesc") %></td> <td><%# DataBinder.Eval(Container.DataItem, "StartTime") %></td> <td><%# DataBinder.Eval(Container.DataItem, "EndTime") %></td> </tr> </ItemTemplate > <AlternatingItemTemplate> <tr style="background-color:Gainsboro;"> <td><%# DataBinder.Eval(Container.DataItem, "ShortDesc") %></td> <td><%# DataBinder.Eval(Container.DataItem, "DetailDesc") %></td> <td><%# DataBinder.Eval(Container.DataItem, "StartTime") %></td> <td><%# DataBinder.Eval(Container.DataItem, "EndTime") %></td> </tr> </AlternatingItemTemplate> <FooterTemplate> </table> </p> </FooterTemplate> </asp:Repeater> </asp:panel> </form> </body> </html> <%-- <?xml version="1.0" standalone="yes"?> <MyCalendar> <Event> <ShortDesc>Gig in Portland - Jazz Club</ShortDesc> <DetailDesc>This should be fun - playing J & T again - be sure to bring the charts.</DetailDesc> <EventDate>2002/07/02</EventDate> <StartTime>6:00PM</StartTime> <EndTime>11:30PM</EndTime> </Event> <Event> <ShortDesc> Rehearsal - Brigadoon</ShortDesc> <DetailDesc>Community Theatre orchestra rehearsal - bring mutes.</DetailDesc> <EventDate>2002/07/14</EventDate> <StartTime>3:30PM</StartTime> <EndTime>6:30PM</EndTime> </Event> <Event> <ShortDesc>.NET Training Class</ShortDesc> <DetailDesc>This should be fun - we'll explore some of the really cool stuff, like ASP.NET server controls and Web Services.</DetailDesc> <EventDate>2002/07/17</EventDate> <StartTime>8:00AM</StartTime> <EndTime>4:30PM</EndTime> </Event> <Event> <ShortDesc>Writing Workshop for Musical Project with Gregg</ShortDesc> <DetailDesc>We're going to brainstorm some ideas and see if we can come up with something great. We're off to a good start.</DetailDesc> <EventDate>2002/07/19</EventDate> <StartTime>10:00AM</StartTime> <EndTime>6:30PM</EndTime> </Event> <Event> <ShortDesc>Community Band</ShortDesc> <DetailDesc>Central park - we'll play everything from standards to shows tunes to classical to marches - you name it. People bring their lawn chairs, eat their dinner, kids play - a great time!</DetailDesc> <EventDate>2002/07/24</EventDate> <StartTime>7:00PM</StartTime> <EndTime>9:00PM</EndTime> </Event> <Event> <ShortDesc>Jam Session at the Beach</ShortDesc> <DetailDesc>Bring more food this time and the crab nets - and the instruments! We'll might stay for a week or so depending on the weather.</DetailDesc> <EventDate>2002/07/21</EventDate> <StartTime>8:00AM</StartTime> <EndTime>11:30PM</EndTime> </Event> <Event> <ShortDesc>Rob's Birthday!</ShortDesc> <DetailDesc>Nothing too fancy - just friends and family. Hope it's a nice day - bike ride would be fun.</DetailDesc> <EventDate>2002/07/30</EventDate> <StartTime>6:09PM</StartTime> <EndTime>11:30PM</EndTime> </Event> <Event> <ShortDesc /> <DetailDesc /> <EventDate /> <StartTime /> <EndTime /> </Event> <Event> <ShortDesc>Event</ShortDesc> <DetailDesc>Number </DetailDesc> <EventDate>Wrox</EventDate> <StartTime>6.00</StartTime> <EndTime>11.30</EndTime> </Event> </MyCalendar> --%>
Database query form Demo (VB.net)
<%--
Code revised from
ASP.NET Tips & Techniques (Paperback)
by Greg Buczek
# Publisher: McGraw-Hill/Osborne Media; 1st edition (May 21, 2002)
# Language: English
# ISBN: 0072225149
--%>
<%@ Page Language=VB Debug=true %>
<%@ Import Namespace="System.Data" %>
<%@ Import Namespace="System.Data.OLEDB" %>
<script runat=server>
Sub SubmitBtn_Click(Sender As Object, E As EventArgs)
Dim DBConn as OleDbConnection
Dim DBCommand As OleDbDataAdapter
Dim DSPageData as New DataSet
Dim TheQuery as String
DBConn = New OleDbConnection( _
"PROVIDER=Microsoft.Jet.OLEDB.4.0;" _
& "DATA SOURCE=" _
& Server.MapPath _
("EmpDB.mdb;"))
TheQuery = "Select " & txtFieldList.Text _
& " From " & txtTableName.Text
If txtWhere.Text <> "" Then
TheQuery = TheQuery & " Where " _
& txtWhere.Text
End If
If txtOrder.Text <> "" Then
TheQuery = TheQuery & " Order By " _
& txtOrder.Text
End If
DBCommand = New OleDbDataAdapter(TheQuery, DBConn)
DBCommand.Fill(DSPageData, _
"QueryResults")
dgQuery.DataSource = _
DSPageData.Tables("QueryResults").DefaultView
dgQuery.DataBind()
End Sub
</SCRIPT>
<HTML>
<HEAD>
<TITLE>Raw Query Page</TITLE>
</HEAD>
<Body LEFTMARGIN="40">
<form runat="server">
<BR><BR>
<asp:label
id="lblMessage2"
font-size="10pt"
font-name="Lucida Console"
text="Enter your query text"
runat="server"
/>
<BR>
Select (Field List)
<BR>
<asp:textbox
id="txtFieldList"
runat="server"
/>
<asp:requiredfieldvalidator
id="rfvFieldList"
controltovalidate="txtFieldList"
display="Dynamic"
font-name="Tahoma"
font-size="10pt"
runat=server>
Field list is required!
</asp:requiredfieldvalidator>
<BR>
From (Table Name)
<BR>
<asp:textbox
id="txtTableName"
runat="server"
/>
<asp:requiredfieldvalidator
id="rfvTableName"
controltovalidate="txtTableName"
display="Dynamic"
font-name="Tahoma"
font-size="10pt"
runat=server>
Field list is required!
</asp:requiredfieldvalidator>
<BR>
Where (Optional)
<BR>
<asp:textbox
id="txtWhere"
runat="server"
/>
<BR>
Order By (Optional)
<BR>
<asp:textbox
id="txtOrder"
runat="server"
/>
<BR>
<asp:button
id="butOK"
text=" OK "
OnClick="SubmitBtn_Click"
runat="server"
/>
<BR><BR>
<asp:datagrid
id="dgQuery"
runat="server"
autogeneratecolumns="True"
/>
</form>
</BODY>
</HTML> Guest Book Demo (C#)
<%@ Page language="c#" src="GuestBook.aspx.cs" AutoEventWireup="false" Inherits="GuestBook.GuestBook" %> <HTML> <body> <form id="Form1" method="post" runat="server"> <P> <asp:DataList id="GuestBookList" runat="server"> <SelectedItemStyle></SelectedItemStyle> <ItemStyle></ItemStyle> <FooterStyle></FooterStyle> <ItemTemplate> Left By: <%# DataBinder.Eval(Container.DataItem, "Author") %> <br> <b> <%# DataBinder.Eval(Container.DataItem, "Message") %> </b> <br> Left On: <%# DataBinder.Eval(Container.DataItem, "Submitted") %> </ItemTemplate> <HeaderStyle></HeaderStyle> </asp:DataList> </P> <DIV style="WIDTH: 560px; POSITION: relative; HEIGHT: 248px" ms_positioning="GridLayout"> <asp:Label id="Label1" runat="server" Width="104px" Height="24px">Your Name:</asp:Label> <asp:Label id="Label2" runat="server" Width="104px" Height="24px">Your Message:</asp:Label> <asp:TextBox id="txtName" runat="server" Width="392px"></asp:TextBox> <asp:TextBox id="txtMessage" runat="server" Width="392px" Height="154px" TextMode="MultiLine"></asp:TextBox> <asp:Button id="cmdSubmit" runat="server" Width="104px" Text="Submit"></asp:Button></DIV> </form> </body> </HTML> <%-- using System; using System.Collections; using System.ComponentModel; using System.Data; using System.Drawing; using System.Web; using System.Web.SessionState; using System.Web.UI; using System.Web.UI.WebControls; using System.Web.UI.HtmlControls; using System.IO; namespace GuestBook { /// <summary> /// Summary description for GuestBook. /// </summary> public class GuestBook : System.Web.UI.Page { protected System.Web.UI.WebControls.DataList GuestBookList; protected System.Web.UI.WebControls.Label Label1; protected System.Web.UI.WebControls.Label Label2; protected System.Web.UI.WebControls.TextBox txtName; protected System.Web.UI.WebControls.TextBox txtMessage; protected System.Web.UI.WebControls.Button cmdSubmit; private string guestBookName; private void Page_Load(object sender, System.EventArgs e) { guestBookName = Server.MapPath("GuestBook"); if (!this.IsPostBack) { GuestBookList.DataSource = GetAllEntries(); GuestBookList.DataBind(); } } #region Web Form Designer generated code override protected void OnInit(EventArgs e) { // // CODEGEN: This call is required by the ASP.NET Web Form Designer. // InitializeComponent(); base.OnInit(e); } /// <summary> /// Required method for Designer support - do not modify /// the contents of this method with the code editor. /// </summary> private void InitializeComponent() { this.cmdSubmit.Click += new System.EventHandler(this.cmdSubmit_Click); this.Load += new System.EventHandler(this.Page_Load); } #endregion private void cmdSubmit_Click(object sender, System.EventArgs e) { BookEntry newEntry = new BookEntry(); newEntry.Author = txtName.Text; newEntry.Submitted = DateTime.Now; newEntry.Message = txtMessage.Text; SaveEntry(newEntry); GuestBookList.DataSource = GetAllEntries(); GuestBookList.DataBind(); txtName.Text = ""; txtMessage.Text = ""; } private ArrayList GetAllEntries() { ArrayList entries = new ArrayList(); DirectoryInfo guestBookDir = new DirectoryInfo(guestBookName); foreach (FileInfo fileItem in guestBookDir.GetFiles()){ entries.Add(GetEntryFromFile(fileItem)); } return entries; } private BookEntry GetEntryFromFile(FileInfo entryFile) { BookEntry newEntry = new BookEntry(); StreamReader r = entryFile.OpenText(); newEntry.Author = r.ReadLine(); newEntry.Submitted = DateTime.Parse(r.ReadLine()); newEntry.Message = r.ReadLine(); r.Close(); return newEntry; } private void SaveEntry(BookEntry entry) { string fileName = guestBookName + @"\"; fileName += DateTime.Now.Ticks.ToString(); FileInfo newFile = new FileInfo(fileName); StreamWriter w = newFile.CreateText(); w.WriteLine(entry.Author); w.WriteLine(entry.Submitted.ToString()); w.WriteLine(entry.Message); w.Flush(); w.Close(); } } public class BookEntry { private string author; private DateTime submitted; private string message; public string Author { get { return author; } set { author = value; } } public DateTime Submitted { get { return submitted; } set { submitted = value; } } public string Message { get { return message; } set { message = value; } } } } --%>
Issue reporter Demo (C#)
<%@ Page language="c#" src="IssueReporter.aspx.cs" AutoEventWireup="false" Inherits="IssueReporter.IssueReporter" %> <HTML> <body> <form id="Form1" method="post" runat="server"> <asp:Label id="Label1" style="Z-INDEX: 101; LEFT: 32px; POSITION: absolute; TOP: 54px" runat="server" Font-Names="Verdana" Font-Size="X-Small">Your Name:</asp:Label> <asp:TextBox id="txtComment" style="Z-INDEX: 107; LEFT: 176px; POSITION: absolute; TOP: 112px" runat="server" Width="384px" Height="112px" TextMode="MultiLine" Font-Names="Verdana" Font-Size="X-Small"></asp:TextBox> <asp:TextBox id="txtSender" style="Z-INDEX: 106; LEFT: 176px; POSITION: absolute; TOP: 80px" runat="server" Width="259px" Height="24px" Font-Names="Verdana" Font-Size="X-Small"></asp:TextBox> <asp:Label id="Label2" style="Z-INDEX: 102; LEFT: 32px; POSITION: absolute; TOP: 86px" runat="server" Font-Names="Verdana" Font-Size="X-Small">Your Email:</asp:Label> <asp:Label id="Label3" style="Z-INDEX: 103; LEFT: 32px; POSITION: absolute; TOP: 118px" runat="server" Width="104px" Height="16px" Font-Names="Verdana" Font-Size="X-Small">Comment:</asp:Label> <asp:CheckBox id="chkPriority" style="Z-INDEX: 104; LEFT: 32px; POSITION: absolute; TOP: 240px" runat="server" Width="416px" Height="24px" Text="Please Reply Immediately!" Font-Names="Verdana" Font-Size="X-Small"></asp:CheckBox> <asp:TextBox id="txtName" style="Z-INDEX: 105; LEFT: 176px; POSITION: absolute; TOP: 48px" runat="server" Width="258px" Height="24px" Font-Names="Verdana" Font-Size="X-Small"></asp:TextBox> <asp:Button id="cmdSend" style="Z-INDEX: 108; LEFT: 32px; POSITION: absolute; TOP: 288px" runat="server" Width="88px" Height="24px" Text="Send"></asp:Button> <asp:Label id="lblResult" style="Z-INDEX: 109; LEFT: 40px; POSITION: absolute; TOP: 352px" runat="server" Width="432px" Height="72px" Font-Names="Verdana" Font-Size="X-Small"></asp:Label> </form> </body> </HTML> <%-- using System; using System.Collections; using System.ComponentModel; using System.Data; using System.Drawing; using System.Web; using System.Web.SessionState; using System.Web.UI; using System.Web.UI.WebControls; using System.Web.UI.HtmlControls; using System.Web.Mail; namespace IssueReporter { /// <summary> /// Summary description for IssueReporter. /// </summary> public class IssueReporter : System.Web.UI.Page { protected System.Web.UI.WebControls.Label Label1; protected System.Web.UI.WebControls.TextBox txtComment; protected System.Web.UI.WebControls.TextBox txtSender; protected System.Web.UI.WebControls.Label Label2; protected System.Web.UI.WebControls.Label Label3; protected System.Web.UI.WebControls.CheckBox chkPriority; protected System.Web.UI.WebControls.TextBox txtName; protected System.Web.UI.WebControls.Button cmdSend; protected System.Web.UI.WebControls.Label lblResult; private void Page_Load(object sender, System.EventArgs e) { // Put user code to initialize the page here } #region Web Form Designer generated code override protected void OnInit(EventArgs e) { // // CODEGEN: This call is required by the ASP.NET Web Form Designer. // InitializeComponent(); base.OnInit(e); } /// <summary> /// Required method for Designer support - do not modify /// the contents of this method with the code editor. /// </summary> private void InitializeComponent() { this.cmdSend.Click += new System.EventHandler(this.cmdSend_Click); this.Load += new System.EventHandler(this.Page_Load); } #endregion private void cmdSend_Click(object sender, System.EventArgs e) { MailMessage msg = new MailMessage(); msg.Subject = "Issue Report"; msg.Body = "Submitted By: " + txtName.Text + "\n"; msg.Body += txtComment.Text; msg.From = txtSender.Text; msg.To = "yourname@youremailserver.com"; if (chkPriority.Checked) msg.Priority = MailPriority.High; SmtpMail.SmtpServer = "localhost"; SmtpMail.Send(msg); lblResult.Text="Message sent to SMTP service."; } } } --%>
Popup menu Demo (C#)
<%@ Page Language="C#" %> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" > <head id="Head1" runat="server"> <style type="text/css"> .staticMenuItem { color:black; border:solid 1px black; padding:2px 4px; } .menuHover { color:white; background-color:blue; } .dynamicMenuItem { color:black; padding:2px 4px; } .dynamicMenu { border:Solid 1px black; filter:progid:DXImageTransform.Microsoft.dropshadow(OffX=5, OffY=5, Color='gray', Positive='true')" } </style> <title>Menu Desktop</title> </head> <body> <form id="form1" runat="server"> <div> <asp:Menu id="Menu1" Orientation="Horizontal" StaticMenuItemStyle-CssClass="staticMenuItem" StaticHoverStyle-CssClass="menuHover" DynamicHoverStyle-CssClass="menuHover" DynamicMenuItemStyle-CssClass="dynamicMenuItem" DynamicMenuStyle-CssClass="dynamicMenu" Runat="server"> <Items> <asp:MenuItem Text="File" Selectable="false"> <asp:MenuItem Text="Save" /> <asp:MenuItem Text="Open" /> </asp:MenuItem> <asp:MenuItem Text="Format" Selectable="false"> <asp:MenuItem Text="Bold" ImageUrl="MenuImages/Bold.gif" /> <asp:MenuItem Text="Italic" ImageUrl="MenuImages/Italic.gif" /> <asp:MenuItem Text="Underline" ImageUrl="MenuImages/Underline.gif" SeparatorImageUrl="Images/Divider.gif" /> <asp:MenuItem Text="Left Align" ImageUrl="MenuImages/JustifyLeft.gif" /> <asp:MenuItem Text="Center Align" ImageUrl="MenuImages/JustifyCenter.gif" /> <asp:MenuItem Text="Right Align" ImageUrl="MenuImages/JustifyRight.gif" /> </asp:MenuItem> </Items> </asp:Menu> </div> </form> </body> </html>
Quiz form Demo (VB.net)
<%--
Code revised from
ASP.NET Tips & Techniques (Paperback)
by Greg Buczek
# Publisher: McGraw-Hill/Osborne Media; 1st edition (May 21, 2002)
# Language: English
# ISBN: 0072225149
--%>
<%@ Page Language=VB Debug=true %>
<script runat=server>
Sub SubmitBtn_Click(Sender As Object, E As EventArgs)
Dim TotalCorrect as Integer
If ddlAnswer1.SelectedItem.Text = "C Sharp" Then
TotalCorrect = TotalCorrect + 1
End If
If ddlAnswer2.SelectedItem.Text = "Visual Basic" Then
TotalCorrect = TotalCorrect + 1
End If
If ddlAnswer3.SelectedItem.Text = "SelectedItem" Then
TotalCorrect = TotalCorrect + 1
End If
lblMessage.Text = "You scored " & TotalCorrect _
& " correct."
End Sub
</SCRIPT>
<HTML>
<HEAD>
<TITLE>Quiz Page</TITLE>
</HEAD>
<form runat="server">
<asp:Label
id="lblMessage"
Font-Size="12pt"
Font-Name="Tahoma"
runat="server"
Text="Complete each question before submitting."
/>
<BR>
How is the new version of "C" pronounced"?
<BR>
<asp:dropdownlist
id="ddlAnswer1"
runat=server
>
<asp:listitem>C Pound</asp:listitem>
<asp:listitem>C Triple Plus</asp:listitem>
<asp:listitem>C Plus Plus Plus</asp:listitem>
<asp:listitem>C Sharp</asp:listitem>
</asp:dropdownlist>
<BR>
What does VB stand for?
<BR>
<asp:dropdownlist
id="ddlAnswer2"
runat=server
>
<asp:listitem>Virtual Basic</asp:listitem>
<asp:listitem>Visual Basic</asp:listitem>
<asp:listitem>Visual Basic</asp:listitem>
<asp:listitem>Vehicle Basic</asp:listitem>
</asp:dropdownlist>
<BR>
What object do you use to retrieve the
item selected by the visitor in a DropDownList control?
<BR>
<asp:dropdownlist
id="ddlAnswer3"
runat=server
>
<asp:listitem>SelectedItem</asp:listitem>
<asp:listitem>SelectItem</asp:listitem>
<asp:listitem>SelectionItem</asp:listitem>
<asp:listitem>SelItem</asp:listitem>
</asp:dropdownlist>
<BR><BR>
<asp:button
id="butOK"
text=" OK "
OnClick="SubmitBtn_Click"
runat="server"
/>
</form>
</BODY>
</HTML>Survey form Demo (VB.net)
<%--
Code revised from
ASP.NET Tips & Techniques (Paperback)
by Greg Buczek
# Publisher: McGraw-Hill/Osborne Media; 1st edition (May 21, 2002)
# Language: English
# ISBN: 0072225149
--%>
<%@ Page Language=VB Debug=true %>
<%@ Import Namespace="System.Data" %>
<%@ Import Namespace="System.Data.OLEDB" %>
<script runat=server>
Sub Page_Load(ByVal Sender as Object, ByVal E as EventArgs)
Application("CurrentQuestion") = 2
If Not IsPostBack Then
Dim DBConn as OleDbConnection
Dim DBCommand As OleDbDataAdapter
Dim DSPageData as New DataSet
DBConn = New OleDbConnection( _
"PROVIDER=Microsoft.Jet.OLEDB.4.0;" _
& "DATA SOURCE=" _
& Server.MapPath _
("SurveyDB.mdb;"))
DBCommand = New OleDbDataAdapter _
("Select SurveyQuestion From " _
& "SurveyQuestions Where SurveyQuestionID = " _
& Application("CurrentQuestion"), DBConn)
DBCommand.Fill(DSPageData, _
"TheQuestion")
lblQuestion.Text = _
DSPageData.Tables("TheQuestion"). _
Rows(0).Item("SurveyQuestion")
DBCommand = New OleDbDataAdapter _
("Select SurveyAnswer From " _
& "SurveyAnswers Where SurveyQuestionID = " _
& Application("CurrentQuestion"), DBConn)
DBCommand.Fill(DSPageData, _
"TheAnswers")
ddlAnswers.DataSource = _
DSPageData.Tables("TheAnswers").DefaultView
ddlAnswers.DataBind()
End If
End Sub
Sub SubmitBtn_Click(Sender As Object, E As EventArgs)
Dim DBConn as OleDbConnection
Dim DBAdd As New OleDbCommand
Dim DBCommand As OleDbDataAdapter
Dim DSPageData as New DataSet
DBConn = New OleDbConnection( _
"PROVIDER=Microsoft.Jet.OLEDB.4.0;" _
& "DATA SOURCE=" _
& Server.MapPath _
("SurveyDB.mdb;"))
DBAdd.CommandText = "Insert Into Responses " _
& "(SurveyQuestionID, Response) values (" _
& Application("CurrentQuestion") & ", " _
& "'" & ddlAnswers.SelectedItem.Text & "')"
DBAdd.Connection = DBConn
DBAdd.Connection.Open
DBAdd.ExecuteNonQuery()
DBCommand = New OleDbDataAdapter _
("Select Response, " _
& "Count(ResponseID) as [Hit Count] " _
& "From Responses " _
& "Where SurveyQuestionID = " _
& Application("CurrentQuestion") _
& " Group By Response", DBConn)
DBCommand.Fill(DSPageData, _
"TheResponses")
dgResponses.DataSource = _
DSPageData.Tables("TheResponses").DefaultView
dgResponses.DataBind()
PanelQuestion.Visible = False
PanelResponse.Visible = True
End Sub
</SCRIPT>
<HTML>
<HEAD>
<TITLE>Survey Page</TITLE>
</HEAD>
<Body LEFTMARGIN="40">
<form runat="server">
<BR><BR>
<asp:label
id="lblQuestion"
font-size="10pt"
font-name="Lucida Console"
runat="server"
/>
<BR>
<asp:panel
id="PanelQuestion"
runat="server"
>
<asp:dropdownlist
id="ddlAnswers"
datatextfield="SurveyAnswer"
runat="server"
/>
<BR><BR>
<asp:button
id="butOK"
text=" OK "
OnClick="SubmitBtn_Click"
runat="server"
/>
</asp:panel>
<BR><BR>
<asp:panel
id="PanelResponse"
runat="server"
visible="False"
>
<asp:datagrid
id="dgResponses"
runat="server"
autogeneratecolumns="True"
/>
</asp:panel>
</form>
</BODY>
</HTML>Tip of the Day Demo (VB.net)
<%--
Code revised from
ASP.NET Tips & Techniques (Paperback)
by Greg Buczek
# Publisher: McGraw-Hill/Osborne Media; 1st edition (May 21, 2002)
# Language: English
# ISBN: 0072225149
--%>
<%@ Page Language=VB Debug=true %>
<%@ Import Namespace="System.Data" %>
<%@ Import Namespace="System.Data.OLEDB" %>
<script runat=server>
Sub Page_Load(ByVal Sender as Object, ByVal E as EventArgs)
Dim DBConn as OleDbConnection
Dim DBCommand As OleDbDataAdapter
Dim DSPageData as New DataSet
If Application("TipDate") <> Today() Then
Application("TipDate") = Today()
If Not Isnumeric(Application("TipNumber")) Then
Application("TipNumber") = 1
Else
Application("TipNumber") = _
Application("TipNumber") + 1
End If
End If
DBConn = New OleDbConnection( _
"PROVIDER=Microsoft.Jet.OLEDB.4.0;" _
& "DATA SOURCE=" _
& Server.MapPath _
("TipDB.mdb;"))
DBCommand = New OleDbDataAdapter _
("Select TipTitle, TipText From Tips " _
& "Where SequenceNumber = " _
& Application("TipNumber"), DBConn)
DBCommand.Fill(DSPageData, _
"TheTip")
If DSPageData.Tables("TheTip").Rows.Count = 0 Then
Application("TipNumber") = 1
DBCommand = New OleDbDataAdapter _
("Select TipTitle, TipText From Tips " _
& "Where SequenceNumber = " _
& Application("TipNumber"), DBConn)
DBCommand.Fill(DSPageData, _
"TheTip")
End If
lblTipTitle.Text = _
DSPageData.Tables("TheTip").Rows(0). _
Item("TipTitle")
lblTipText.Text = _
DSPageData.Tables("TheTip").Rows(0). _
Item("TipText")
End Sub
</SCRIPT>
<HTML>
<HEAD>
<TITLE>Tip of the Day</TITLE>
</HEAD>
<Body LEFTMARGIN="40">
<form runat="server">
<BR><BR>
<asp:label
id="lblTitle"
font-size="12pt"
font-bold="True"
font-name="Lucida Console"
runat="server"
text="Current Tip of the Day"
/>
<BR><BR>
<asp:label
id="lblTipTitle"
font-size="10pt"
font-name="Lucida Console"
runat="server"
/>
<BR>
<asp:label
id="lblTipText"
font-size="10pt"
font-name="Lucida Console"
runat="server"
/>
</form>
</BODY>
</HTML>What is new form (VB.net)
<%@ Page Language=VB Debug=true %> <%@ Import Namespace="System.Data" %> <%@ Import Namespace="System.Data.OLEDB" %> <script runat=server> Sub Page_Load(ByVal Sender as Object, ByVal E as EventArgs) If Not IsPostBack Then Dim DBConn as OleDbConnection Dim DBCommand As OleDbDataAdapter Dim DSPageData as New DataSet DBConn = New OleDbConnection( _ "PROVIDER=Microsoft.Jet.OLEDB.4.0;" _ & "DATA SOURCE=" _ & Server.MapPath _ ("WhatsNewDB.mdb;")) DBCommand = New OleDbDataAdapter _ ("Select Top 1 TheNews From News " _ & "Order By DateEntered Desc", DBConn) DBCommand.Fill(DSPageData, _ "News") lblTheNews.Text = _ DSPageData.Tables("News").Rows(0). _ Item("TheNews") DBCommand = New OleDbDataAdapter _ ("Select NewsID, DateEntered From News " _ & "Order By DateEntered DESC", DBConn) DBCommand.Fill(DSPageData, _ "NewsDates") ddlNews.DataSource = _ DSPageData.Tables("NewsDates").DefaultView ddlNews.DataBind() End If End Sub Sub ddlNews_Changed(Sender As Object, E As EventArgs) Dim DBConn as OleDbConnection Dim DBCommand As OleDbDataAdapter Dim DSPageData as New DataSet DBConn = New OleDbConnection( _ "PROVIDER=Microsoft.Jet.OLEDB.4.0;" _ & "DATA SOURCE=" _ & Server.MapPath _ ("WhatsNewDB.mdb;")) DBCommand = New OleDbDataAdapter _ ("Select TheNews From News " _ & "Where NewsID = " & ddlNews.SelectedItem.Value _ , DBConn) DBCommand.Fill(DSPageData, _ "News") lblTheNews.Text = _ DSPageData.Tables("News").Rows(0). _ Item("TheNews") End Sub </SCRIPT> <HTML> <HEAD> <TITLE>What's New</TITLE> </HEAD> <Body LEFTMARGIN="40"> <form runat="server"> <BR><BR> <asp:label id="lblTheNews" font-size="12pt" font-bold="True" font-name="Lucida Console" runat="server" /> <BR><BR> <asp:label id="lblMessage2" font-size="10pt" font-name="Lucida Console" text="View old News" runat="server" /> <BR> <asp:dropdownlist id="ddlNews" datatextfield="DateEntered" datavaluefield="NewsID" autopostback="True" onselectedindexchanged="ddlNews_Changed" runat="server" /> </form> </BODY> </HTML>
Use Image as the indicator for validation (C#)
<%@ Page Language="C#" %> <html> <body> <form runat=server> <table cellspacing=10 cellpadding=2 border=0> <tr> <td> <table cellspacing=0 cellpadding=1 border=0> <tr valign=top> <td/> <td align=left><b><u>Account information:</u></b></td> </tr> <tr valign=top> <td align=right><b>First name:</b></td> <td><asp:TextBox ID="firstname" width=160 MaxLength=16 Text="" runat=server/></td> <td><asp:RequiredFieldValidator id="FirstNameValidator" ControlToValidate="firstname" Display="Static" ErrorMessage="First name must be filled in." InitialValue="" width="100%" runat=server> <img src="oops.gif"/> </asp:RequiredFieldValidator></td> </tr> <tr valign=top> <td align=right><b>Last name:</b></td> <td><asp:TextBox ID="lastname" width=160 MaxLength=16 Text="" runat=server/></td> <td><asp:RequiredFieldValidator id="LastNameValidator" ControlToValidate="lastname" Display="Static" ErrorMessage="Last name must be filled in." InitialValue="" width="100%" runat=server> <img src="oops.gif"/> </asp:RequiredFieldValidator></td> </tr> <tr valign=top> <td align=right><b>E-mail address:</b></td> <td><asp:TextBox ID="email" width=160 MaxLength=64 Text="" runat=server/> <br/>(e.g. joe@foo.com) </td> <td> <asp:RequiredFieldValidator id="EmailValidator" ControlToValidate="email" Display="Dynamic" ErrorMessage="E-mail address must be filled in." InitialValue="" width="100%" runat=server> <img src="oops.gif"/> </asp:RequiredFieldValidator> <asp:RegularExpressionValidator id="EmailRegexValidator" ControlToValidate="email" Display="Dynamic" ErrorMessage="E-mail must be of the form joe@develop.com." InitialValue="" width="100%" runat=server ValidationExpression="[\w-]+@[\w-]+\.(com|net|org|edu|mil)$"> <img src="oops.gif"/> </asp:RegularExpressionValidator> </td> </tr> <tr valign=top> <td align=right><b>Password:</b></td> <td><asp:TextBox ID="password" TextMode="Password" width=160 MaxLength=10 Text="" runat=server/> <br/>(4 to 10 characters) </td> <td><asp:RequiredFieldValidator id="PasswordValidator" ControlToValidate="password" Display="Dynamic" ErrorMessage="Password must be filled in." InitialValue="" width="100%" runat=server> <img src="oops.gif"/> </asp:RequiredFieldValidator> <asp:CompareValidator id="PasswordCompareValidator" ControlToValidate="password" ControlToCompare="confirm" Display="None" ErrorMessage="The two passwords you entered did not match, please reenter" Type="String" Operator="Equal" runat=server /> </td> </tr> <tr valign=top> <td align=right><b>Re-enter password:</b></td> <td><asp:TextBox ID="confirm" width=160 MaxLength=10 Text="" TextMode="Password" runat=server/> </td> <td><asp:RequiredFieldValidator id="ConfirmValidator" ControlToValidate="confirm" Display="Dynamic" ErrorMessage="Re-enter password must be filled in." InitialValue="" width="100%" runat=server> <img src="oops.gif"/> </asp:RequiredFieldValidator></td> </tr> <tr valign=top> <td/> <td align=left><b><u>Shipping Address</u></b></td> </tr> <tr valign=top> <td align=right><b>Company:</b></td> <td><asp:TextBox ID="company" width=160 MaxLength=64 Text="" runat=server/> </td> </tr> <tr valign=top> <td align=right><b>Address Line 1:</b></td> <td><asp:TextBox ID="address1" width=160 MaxLength=64 Text="" runat=server/> </td> <td><asp:RequiredFieldValidator id="Address1Validator" ControlToValidate="address1" Display="Static" ErrorMessage="Address Line 1 must be filled in." InitialValue="" width="100%" runat=server> <img src="oops.gif"/> </asp:RequiredFieldValidator></td> </tr> <tr valign=top> <td align=right><b>Address Line 2:</b></td> <td><asp:TextBox ID="address2" width=160 MaxLength=64 Text="" runat=server/> </td> </tr> <tr valign=top> <td align=right><b>City:</b></td> <td><asp:TextBox ID="city" width=160 MaxLength=64 Text="" runat=server/> </td> <td><asp:RequiredFieldValidator id="CityValidator" ControlToValidate="city" Display="Static" ErrorMessage="City must be filled in." InitialValue="" width="100%" runat=server> <img src="oops.gif"/> </asp:RequiredFieldValidator></td> </tr> <tr valign=top> <td align=right><b>State/Province:</b></td> <td><asp:TextBox ID="stateprovince" width=160 MaxLength=64 Text="" runat=server/> </td> <td><asp:RequiredFieldValidator id="StateValidator" ControlToValidate="stateprovince" Display="Static" ErrorMessage="State/Province must be filled in." InitialValue="" width="100%" runat=server> <img src="oops.gif"/> </asp:RequiredFieldValidator></td> </tr> <tr valign=top> <td align=right><b>Zip/Postal Code:</b></td> <td><asp:TextBox ID="zipcode" width=120 MaxLength=11 Text="" runat=server/> </td> <td> <asp:RequiredFieldValidator id="ZipcodeValidator" ControlToValidate="zipcode" Display="Dynamic" ErrorMessage="Zip/Postal Code must be filled in." InitialValue="" width="100%" runat=server> <img src="oops.gif"/> </asp:RequiredFieldValidator> <asp:RegularExpressionValidator id="ZipcodeRegexValidator" ControlToValidate="zipcode" Display="Dynamic" ErrorMessage="Zip/Postal Code must be 5 numerals." InitialValue="" width="100%" ValidationExpression="\d{5}$" runat=server> <img src="oops.gif"/> </asp:RegularExpressionValidator> </td> </tr> <tr valign=top> <td align=right><b>Country:</b></td> <td><asp:DropDownList id="country" runat=server> <asp:ListItem select=True></asp:ListItem> <asp:ListItem>United States</asp:ListItem> <asp:ListItem>Albania</asp:ListItem> <asp:ListItem>Algeria</asp:ListItem> <asp:ListItem>Andorra</asp:ListItem> <asp:ListItem>Angola</asp:ListItem> <asp:ListItem>Anguilla</asp:ListItem> <asp:ListItem>Antigua</asp:ListItem> <asp:ListItem>Argentina</asp:ListItem> <asp:ListItem>Armenia</asp:ListItem> <asp:ListItem>Aruba</asp:ListItem> <asp:ListItem>Australia</asp:ListItem> <asp:ListItem>Austria</asp:ListItem> <asp:ListItem>Azerbaijan</asp:ListItem> <asp:ListItem>Azores</asp:ListItem> <asp:ListItem>Bahamas</asp:ListItem> <asp:ListItem>Bahrain</asp:ListItem> <asp:ListItem>Bangladesh</asp:ListItem> <asp:ListItem>Barbados</asp:ListItem> <asp:ListItem>Belarus</asp:ListItem> <asp:ListItem>Belgium</asp:ListItem> <asp:ListItem>Belize</asp:ListItem> <asp:ListItem>Benin</asp:ListItem> <asp:ListItem>Bermuda</asp:ListItem> <asp:ListItem>Bhutan</asp:ListItem> <asp:ListItem>Bolivia</asp:ListItem> <asp:ListItem>Bosnia-Herzegovina</asp:ListItem> <asp:ListItem>Botswana</asp:ListItem> <asp:ListItem>Brazil</asp:ListItem> <asp:ListItem>British Virgin Islands</asp:ListItem> <asp:ListItem>Brunei</asp:ListItem> <asp:ListItem>Bulgaria</asp:ListItem> <asp:ListItem>Burkina Faso</asp:ListItem> <asp:ListItem>Burundi</asp:ListItem> <asp:ListItem>Cambodia</asp:ListItem> <asp:ListItem>Cameroon</asp:ListItem> <asp:ListItem>Canada</asp:ListItem> <asp:ListItem>Cape Verde</asp:ListItem> <asp:ListItem>Cayman Islands</asp:ListItem> <asp:ListItem>Central African Republic</asp:ListItem> <asp:ListItem>Chad</asp:ListItem> <asp:ListItem>Chile</asp:ListItem> <asp:ListItem>China</asp:ListItem> <asp:ListItem>Colombia</asp:ListItem> <asp:ListItem>Comoros</asp:ListItem> <asp:ListItem>Congo</asp:ListItem> <asp:ListItem>Corsica</asp:ListItem> <asp:ListItem>Costa Rica</asp:ListItem> <asp:ListItem>Croatia</asp:ListItem> <asp:ListItem>Cyprus</asp:ListItem> <asp:ListItem>Czech Republic</asp:ListItem> <asp:ListItem>Denmark</asp:ListItem> <asp:ListItem>Djibouti</asp:ListItem> <asp:ListItem>Dominica</asp:ListItem> <asp:ListItem>Dominican Republic</asp:ListItem> <asp:ListItem>Ecuador</asp:ListItem> <asp:ListItem>Egypt</asp:ListItem> <asp:ListItem>El Salvador</asp:ListItem> <asp:ListItem>England</asp:ListItem> <asp:ListItem>Equatorial Guinea</asp:ListItem> <asp:ListItem>Eritrea</asp:ListItem> <asp:ListItem>Estonia</asp:ListItem> <asp:ListItem>Ethiopia</asp:ListItem> <asp:ListItem>Faroe Islands</asp:ListItem> <asp:ListItem>Fiji</asp:ListItem> <asp:ListItem>Finland</asp:ListItem> <asp:ListItem>France</asp:ListItem> <asp:ListItem>French Guiana</asp:ListItem> <asp:ListItem>French Polynesia</asp:ListItem> <asp:ListItem>Gabon</asp:ListItem> <asp:ListItem>Gambia</asp:ListItem> <asp:ListItem>Georgia</asp:ListItem> <asp:ListItem>Germany</asp:ListItem> <asp:ListItem>Ghana</asp:ListItem> <asp:ListItem>Gibraltar</asp:ListItem> <asp:ListItem>Great Britain</asp:ListItem> <asp:ListItem>Greece</asp:ListItem> <asp:ListItem>Greenland</asp:ListItem> <asp:ListItem>Grenada</asp:ListItem> <asp:ListItem>Guadeloupe</asp:ListItem> <asp:ListItem>Guatemala</asp:ListItem> <asp:ListItem>Guinea</asp:ListItem> <asp:ListItem>Guinea-Bissau</asp:ListItem> <asp:ListItem>Guyana</asp:ListItem> <asp:ListItem>Haiti</asp:ListItem> <asp:ListItem>Honduras</asp:ListItem> <asp:ListItem>Hong Kong</asp:ListItem> <asp:ListItem>Hungary</asp:ListItem> <asp:ListItem>Iceland</asp:ListItem> <asp:ListItem>India</asp:ListItem> <asp:ListItem>Indonesia</asp:ListItem> <asp:ListItem>Ireland</asp:ListItem> <asp:ListItem>Israel</asp:ListItem> <asp:ListItem>Italy</asp:ListItem> <asp:ListItem>Ivory Coast</asp:ListItem> <asp:ListItem>Jamaica</asp:ListItem> <asp:ListItem>Japan</asp:ListItem> <asp:ListItem>Jordan</asp:ListItem> <asp:ListItem>Kampuchea</asp:ListItem> <asp:ListItem>Kazakhstan</asp:ListItem> <asp:ListItem>Kenya</asp:ListItem> <asp:ListItem>Kiribati</asp:ListItem> <asp:ListItem>Korea</asp:ListItem> <asp:ListItem>Kuwait</asp:ListItem> <asp:ListItem>Kyrgyzstan</asp:ListItem> <asp:ListItem>Laos</asp:ListItem> <asp:ListItem>Latvia</asp:ListItem> <asp:ListItem>Lebanon</asp:ListItem> <asp:ListItem>Lesotho</asp:ListItem> <asp:ListItem>Liberia</asp:ListItem> <asp:ListItem>Liechtenstein</asp:ListItem> <asp:ListItem>Lithuania</asp:ListItem> <asp:ListItem>Luxembourg</asp:ListItem> <asp:ListItem>Macao</asp:ListItem> <asp:ListItem>Macedonia</asp:ListItem> <asp:ListItem>Madagascar</asp:ListItem> <asp:ListItem>Madeira Islands</asp:ListItem> <asp:ListItem>Malawi</asp:ListItem> <asp:ListItem>Malaysia</asp:ListItem> <asp:ListItem>Maldives</asp:ListItem> <asp:ListItem>Mali</asp:ListItem> <asp:ListItem>Malta</asp:ListItem> <asp:ListItem>Martinique</asp:ListItem> <asp:ListItem>Mauritania</asp:ListItem> <asp:ListItem>Mauritius</asp:ListItem> <asp:ListItem>Mexico</asp:ListItem> <asp:ListItem>Moldova</asp:ListItem> <asp:ListItem>Mongolia</asp:ListItem> <asp:ListItem>Montserrat</asp:ListItem> <asp:ListItem>Morocco</asp:ListItem> <asp:ListItem>Mozambique</asp:ListItem> <asp:ListItem>Namibia</asp:ListItem> <asp:ListItem>Nauru</asp:ListItem> <asp:ListItem>Nepal</asp:ListItem> <asp:ListItem>Netherlands</asp:ListItem> <asp:ListItem>Netherlands Antilles</asp:ListItem> <asp:ListItem>New Caledonia</asp:ListItem> <asp:ListItem>New Zealand</asp:ListItem> <asp:ListItem>Nicaragua</asp:ListItem> <asp:ListItem>Niger</asp:ListItem> <asp:ListItem>Nigeria</asp:ListItem> <asp:ListItem>Northern Ireland</asp:ListItem> <asp:ListItem>Norway</asp:ListItem> <asp:ListItem>Oman</asp:ListItem> <asp:ListItem>Pakistan</asp:ListItem> <asp:ListItem>Panama</asp:ListItem> <asp:ListItem>Papua New Guinea</asp:ListItem> <asp:ListItem>Paraguay</asp:ListItem> <asp:ListItem>Peru</asp:ListItem> <asp:ListItem>Philippines</asp:ListItem> <asp:ListItem>Poland</asp:ListItem> <asp:ListItem>Portugal</asp:ListItem> <asp:ListItem>Qatar</asp:ListItem> <asp:ListItem>Reunion</asp:ListItem> <asp:ListItem>Romania</asp:ListItem> <asp:ListItem>Russia</asp:ListItem> <asp:ListItem>Rwanda</asp:ListItem> <asp:ListItem>Saint Kitts & Nevis</asp:ListItem> <asp:ListItem>Saint Lucia</asp:ListItem> <asp:ListItem>Saint Vincent</asp:ListItem> <asp:ListItem>San Marino</asp:ListItem> <asp:ListItem>Sao Tome and Principe</asp:ListItem> <asp:ListItem>Saudi Arabia</asp:ListItem> <asp:ListItem>Scotland</asp:ListItem> <asp:ListItem>Senegal</asp:ListItem> <asp:ListItem>Seychelles</asp:ListItem> <asp:ListItem>Sierra Leone</asp:ListItem> <asp:ListItem>Singapore</asp:ListItem> <asp:ListItem>Slovakia</asp:ListItem> <asp:ListItem>Slovenia</asp:ListItem> <asp:ListItem>Solomon Islands</asp:ListItem> <asp:ListItem>Somalia</asp:ListItem> <asp:ListItem>South Africa</asp:ListItem> <asp:ListItem>South Korea</asp:ListItem> <asp:ListItem>Spain</asp:ListItem> <asp:ListItem>Sri Lanka</asp:ListItem> <asp:ListItem>Sudan</asp:ListItem> <asp:ListItem>Suriname</asp:ListItem> <asp:ListItem>Swaziland</asp:ListItem> <asp:ListItem>Sweden</asp:ListItem> <asp:ListItem>Switzerland</asp:ListItem> <asp:ListItem>Syria</asp:ListItem> <asp:ListItem>Taiwan</asp:ListItem> <asp:ListItem>Tajikistan</asp:ListItem> <asp:ListItem>Tanzania</asp:ListItem> <asp:ListItem>Thailand</asp:ListItem> <asp:ListItem>Togo</asp:ListItem> <asp:ListItem>Tonga</asp:ListItem> <asp:ListItem>Trinidad & Tobago</asp:ListItem> <asp:ListItem>Tunisia</asp:ListItem> <asp:ListItem>Turkey</asp:ListItem> <asp:ListItem>Turkmenistan</asp:ListItem> <asp:ListItem>Turks and Caicos Islands</asp:ListItem> <asp:ListItem>Tuvalu</asp:ListItem> <asp:ListItem>Uganda</asp:ListItem> <asp:ListItem>Ukraine</asp:ListItem> <asp:ListItem>United Arab Emirates</asp:ListItem> <asp:ListItem>United States</asp:ListItem> <asp:ListItem>Uruguay</asp:ListItem> <asp:ListItem>Uzbekistan</asp:ListItem> <asp:ListItem>Vanuatu</asp:ListItem> <asp:ListItem>Vatican City</asp:ListItem> <asp:ListItem>Venezuela</asp:ListItem> <asp:ListItem>Vietnam</asp:ListItem> <asp:ListItem>Wales</asp:ListItem> <asp:ListItem>Wallis and Futuna Islands</asp:ListItem> <asp:ListItem>Western Samoa</asp:ListItem> <asp:ListItem>Yemen</asp:ListItem> <asp:ListItem>Zaire</asp:ListItem> <asp:ListItem>Zambia</asp:ListItem> <asp:ListItem>Zimbabwe</asp:ListItem> </asp:DropDownList></td> <td><asp:RequiredFieldValidator id="CountryValidator" ControlToValidate="country" Display="Static" ErrorMessage="Country must be filled in." InitialValue="" width="100%" runat=server> <img src="oops.gif"/> </asp:RequiredFieldValidator></td> </tr> <tr valign=top> <td align=right><b>Day Phone:</b></td> <td><asp:TextBox ID="dayphone" width=160 MaxLength=64 Text="" runat=server/> </td> <td> <asp:RequiredFieldValidator id="DayphoneValidator" ControlToValidate="dayphone" Display="Dynamic" ErrorMessage="Day Phone must be filled in." InitialValue="" width="100%" runat=server> <img src="oops.gif"/> </asp:RequiredFieldValidator> <asp:RegularExpressionValidator id="DayphoneRegexValidator" ControlToValidate="dayphone" Display="Dynamic" ErrorMessage="The Day Phone must be formatted like (818) 555-1212." ValidationExpression="(\s*[0-9]{5}$)|(^(\([1-9][0-9]{2}\)\s)?[1-9][0-9]{2}-[0-9]{4}(\sx\s*[0-9]{5})?$)" InitialValue="" width="100%" runat=server> <img src="oops.gif"/> </asp:RegularExpressionValidator> </td> </tr> <tr> <td><br></td> <td colspan=2><br> <asp:Button Text="Submit" runat=server/> </td> </tr> </table> </td> <td> <asp:ValidationSummary id="valSum" runat=server HeaderText="Please correct the following errors:" ShowMessageBox="True"/> </td> </tr> </table> </form> </body> </html>
Simplest Progress Bar (VB.net)
<%@ Page Language="vb" %> <html> <head> <title>Buffering Output in ASP.NET</title> <script runat="server"> Sub Page_Load() Response.BufferOutput = False Dim i As Integer For i = 1 To 50 If (i > 10 And i < 30) Then Response.BufferOutput = True Else Response.BufferOutput = False End If System.Threading.Thread.Sleep(500) Response.Write(".") Message.Text &= "." Next Response.Write("</br>Done!</br>") Message.Text &= "</br>Done!</br>" End Sub </script> </head> <body> <asp:label id="Message" runat="server"/> </body> </html>
Phone Book Demo (VB.net)
<%-- Code revised from ASP.NET Tips & Techniques (Paperback) by Greg Buczek # Publisher: McGraw-Hill/Osborne Media; 1st edition (May 21, 2002) # Language: English # ISBN: 0072225149 --%> <%@ Page Language=VB Debug=true %> <%@ Import Namespace="System.Data" %> <%@ Import Namespace="System.Data.OLEDB" %> <script runat=server> Sub Page_Load(ByVal Sender as Object, ByVal E as EventArgs) If Not IsPostBack Then Dim DBConn as OleDbConnection Dim DBCommand As OleDbDataAdapter Dim DSPageData as New DataSet DBConn = New OleDbConnection( _ "PROVIDER=Microsoft.Jet.OLEDB.4.0;" _ & "DATA SOURCE=" _ & Server.MapPath _ ("PhoneDir.mdb;")) DBCommand = New OleDbDataAdapter _ ("Select EmpName as [Employee Name], " _ & "Department, PhoneNumber as " _ & "[Phone Number] From Emps " _ & "Order By EmpName", DBConn) DBCommand.Fill(DSPageData, _ "Employees") dgEmps.DataSource = _ DSPageData.Tables("Employees").DefaultView dgEmps.DataBind() DBCommand = New OleDbDataAdapter _ ("Select Distinct Department From Emps " _ & "Order By Department", DBConn) DBCommand.Fill(DSPageData, _ "Departments") ddlDepartments.DataSource = _ DSPageData.Tables("Departments").DefaultView ddlDepartments.DataBind() End If End Sub Sub ddl1_Changed(Sender As Object, E As EventArgs) Dim DBConn as OleDbConnection Dim DBCommand As OleDbDataAdapter Dim DSPageData as New DataSet DBConn = New OleDbConnection( _ "PROVIDER=Microsoft.Jet.OLEDB.4.0;" _ & "DATA SOURCE=" _ & Server.MapPath _ ("PhoneDir.mdb;")) DBCommand = New OleDbDataAdapter _ ("Select EmpName as [Employee Name], " _ & "Department, PhoneNumber as " _ & "[Phone Number] From Emps " _ & "Where Department = '" _ & ddlDepartments.SelectedItem.Text _ & "' Order By EmpName", DBConn) DBCommand.Fill(DSPageData, _ "Employees") dgEmps.DataSource = _ DSPageData.Tables("Employees").DefaultView dgEmps.DataBind() End Sub </SCRIPT> <HTML> <HEAD> <TITLE>Phone Directory</TITLE> </HEAD> <Body LEFTMARGIN="40"> <form runat="server"> <BR><BR> <asp:label id="lblMessage1" font-size="12pt" font-bold="True" font-name="Lucida Console" text="Phone Number List" runat="server" /> <BR><BR> <asp:datagrid id="dgEmps" runat="server" autogeneratecolumns="True" /> <BR><BR> <asp:label id="lblMessage2" font-size="10pt" font-name="Lucida Console" text="Filter by Department" runat="server" /> <BR> <asp:dropdownlist id="ddlDepartments" datatextfield="Department" autopostback="True" onselectedindexchanged="ddl1_Changed" runat="server" /> </form> </BODY> </HTML>
Use Multiview to handle form submission (C#)
/* ASP.NET 2.0 Unleashed (Unleashed) (Hardcover) by Stephen Walther # Publisher: Sams; Bk&CD-Rom edition (June 6, 2006) # Language: English # ISBN: 0672328232 */ <%@ Page Language="C#" %> <script runat="server"> protected void View3_Activate(object sender, EventArgs e) { lblFirstNameResult.Text = txtFirstName.Text; lblColorResult.Text = txtColor.Text; } </script> <html xmlns="http://www.w3.org/1999/xhtml" > <head id="Head1" runat="server"> <title>MultiView Form</title> </head> <body> <form id="form1" runat="server"> <div> <asp:MultiView id="MultiView1" ActiveViewIndex="0" Runat="server"> <asp:View ID="View1" runat="server"> <h1>Step 1</h1> <asp:Label id="lblFirstName" Text="Enter Your First Name:" AssociatedControlID="txtFirstName" Runat="server" /> <br /> <asp:TextBox id="txtFirstName" Runat="server" /> <br /><br /> <asp:Button id="btnNext" Text="Next" CommandName="NextView" Runat="server" /> </asp:View> <asp:View ID="View2" runat="server"> <h1>Step 2</h1> <asp:Label id="Label1" Text="Enter Your Favorite Color:" AssociatedControlID="txtColor" Runat="server" /> <br /> <asp:TextBox id="txtColor" Runat="server" /> <br /><br /> <asp:Button id="Button1" Text="Next" CommandName="NextView" Runat="server" /> </asp:View> <asp:View ID="View3" runat="server" OnActivate="View3_Activate"> <h1>Summary</h1> Your First Name: <asp:Label id="lblFirstNameResult" Runat="server" /> <br /><br /> Your Favorite Color: <asp:Label id="lblColorResult" Runat="server" /> </asp:View> </asp:MultiView> </div> </form> </body> </html>
Login form Demo (VB.net)
<%-- Code revised from ASP.NET Tips & Techniques (Paperback) by Greg Buczek # Publisher: McGraw-Hill/Osborne Media; 1st edition (May 21, 2002) # Language: English # ISBN: 0072225149 --%> <%@ Page Language=VB Debug=true %> <%@ Import Namespace="System.Data" %> <%@ Import Namespace="System.Data.OLEDB" %> <script runat=server> Sub SubmitBtn_Click(Sender As Object, E As EventArgs) Dim DBConn as OleDbConnection Dim DBCommand As OleDbDataAdapter Dim DSLogin as New DataSet DBConn = New OleDbConnection("PROVIDER=" _ & "Microsoft.Jet.OLEDB.4.0;" _ & "DATA SOURCE=" _ & Server.MapPath("LogIn.mdb;")) DBCommand = New OleDbDataAdapter _ ("Select UserID from " _ & "Users Where " _ & "UserName = '" & txtUserName.Text _ & "' and Password = '" & txtPassword.Text _ & "'", DBConn) DBCommand.Fill(DSLogin, _ "UserInfo") If DSLogin.Tables("UserInfo"). _ Rows.Count = 0 Then lblMessage.Text = "The user name and password " _ & "were not found. Please try again." Else Session("UserID") = DSLogin.Tables("UserInfo"). _ Rows(0).Item("UserID") Session("UserName") = txtUserName.Text Response.Redirect("./welcome.aspx") End If End Sub </SCRIPT> <HTML> <HEAD> <TITLE>Log In Page</TITLE> </HEAD> <form runat="server"> <asp:Label id="lblMessage" Font-Size="12pt" Font-Name="Tahoma" runat="server" Text="Complete each field to enter the site." /> <P></P><Font Face="Tahoma">User Name:</Font><BR> <asp:TextBox id="txtUserName" Columns="25" MaxLength="50" runat=server /> <asp:RequiredFieldValidator id="rfvUserName" ControlToValidate="txtUserName" Display="Dynamic" Font-Name="Tahoma" Font-Size="10pt" runat=server> User Name is Required! </asp:RequiredFieldValidator> <P></P><Font Face="Tahoma">Password:</Font><BR> <asp:TextBox id="txtPassword" Columns="25" MaxLength="50" runat=server TextMode="Password" /> <asp:RequiredFieldValidator id="rfvPassword" ControlToValidate="txtPassword" Display="Dynamic" Font-Name="Verdana" Font-Size="10pt" runat=server> Password is Required! </asp:RequiredFieldValidator><BR><BR> <asp:button id="butOK" text=" OK " OnClick="SubmitBtn_Click" runat="server" /> </form> </BODY> </HTML> <%-- Welcome.aspx <%@ Page Language=VB Debug=true %> <script runat=server> Sub Page_Load(ByVal Sender as Object, ByVal E as EventArgs) If Len(Session("UserID")) = 0 Then Response.Redirect("./login.aspx") End If lblMessage.Text = "Welcome: " & Session("UserName") End Sub </SCRIPT> <HTML> <HEAD> <TITLE>Welcome Page</TITLE> </HEAD> <form runat="server"> <asp:Label id="lblMessage" Font-Size="12pt" Font-Name="Tahoma" runat="server" /> </form> </BODY> </HTML> --%>
Help wizard form (VB.net)
<%--
Code revised from
ASP.NET Tips & Techniques (Paperback)
by Greg Buczek
# Publisher: McGraw-Hill/Osborne Media; 1st edition (May 21, 2002)
# Language: English
# ISBN: 0072225149
--%>
<%@ Page Language=VB EnableSessionState=true Debug=true %>
<%@ Import Namespace="System.Data" %>
<%@ Import Namespace="System.Data.OLEDB" %>
<script runat=server>
Sub Page_Load(ByVal Sender as Object, ByVal E as EventArgs)
If Not IsPostBack then
Dim DBConn as OleDbConnection
Dim DBCommand As OleDbDataAdapter
Dim DSPageData as New DataSet
DBConn = New OleDbConnection( _
"PROVIDER=Microsoft.Jet.OLEDB.4.0;" _
& "DATA SOURCE=" _
& Server.MapPath _
("HelpDeskDB.mdb;"))
DBCommand = New OleDbDataAdapter _
("Select QuestionID, TitleText, TheMessage " _
& "From HelpDesk Where ParentID = 0", DBConn)
DBCommand.Fill(DSPageData, _
"Question")
DBCommand = New OleDbDataAdapter _
("Select QuestionID, TheChoice " _
& "From HelpDesk " _
& "Where ParentID = " _
& DSPageData.Tables("Question"). _
Rows(0).Item("QuestionID") _
,DBConn)
DBCommand.Fill(DSPageData, _
"Choices")
lblTitle.Text = "Help Desk - " _
& DSPageData.Tables("Question"). _
Rows(0).Item("TitleText")
lblQuestion.Text = _
DSPageData.Tables("Question"). _
Rows(0).Item("TheMessage")
ddlAnswers.DataSource = _
DSPageData.Tables("Choices").DefaultView
ddlAnswers.DataBind()
End If
End Sub
Sub SubmitBtn_Click(Sender As Object, E As EventArgs)
Dim DBConn as OleDbConnection
Dim DBCommand As OleDbDataAdapter
Dim DSPageData as New DataSet
DBConn = New OleDbConnection( _
"PROVIDER=Microsoft.Jet.OLEDB.4.0;" _
& "DATA SOURCE=" _
& Server.MapPath _
("HelpDeskDB.mdb;"))
DBCommand = New OleDbDataAdapter _
("Select QorA, TitleText, TheMessage " _
& "From HelpDesk Where QuestionID = " _
& ddlAnswers.SelectedItem.Value,DBConn)
DBCommand.Fill(DSPageData, _
"Question")
lblTitle.Text = "Help Desk - " _
& DSPageData.Tables("Question"). _
Rows(0).Item("TitleText")
lblQuestion.Text = _
DSPageData.Tables("Question"). _
Rows(0).Item("TheMessage")
If DSPageData.Tables("Question"). _
Rows(0).Item("QorA") = "Q" Then
DBCommand = New OleDbDataAdapter _
("Select QuestionID, TheChoice " _
& "From HelpDesk " _
& "Where ParentID = " _
& ddlAnswers.SelectedItem.Value,DBConn)
DBCommand.Fill(DSPageData, _
"Choices")
ddlAnswers.DataSource = _
DSPageData.Tables("Choices").DefaultView
ddlAnswers.DataBind()
Else
ddlAnswers.Visible = False
butOK.Visible = False
End If
End Sub
</script>
<HTML>
<HEAD>
<TITLE>Help Desk</TITLE>
</HEAD>
<Body LEFTMARGIN="40">
<form runat="server">
<CENTER>
<asp:Label
id="lblTitle"
runat="server"
/>
</CENTER>
<P></P>
<asp:Label
id="lblQuestion"
runat="server"
/>
<P></P>
<asp:dropdownlist
id="ddlAnswers"
runat=server
DataTextField="TheChoice"
DataValueField="QuestionID">
</asp:dropdownlist>
<P></P>
<asp:button
id="butOK"
text="OK"
Type="Submit"
OnClick="SubmitBtn_Click"
runat="server"
/>
</FORM>
</BODY>
</HTML>Contact Page (VB.net)
<%@ Page Language=VB Debug=true %> <%@ Import Namespace="System.Data" %> <%@ Import Namespace="System.Data.OLEDB" %> <script runat=server> Sub SubmitBtn_Click(Sender As Object, E As EventArgs) Dim DBConn as OleDbConnection Dim DBAdd As New OleDbCommand DBConn = New OleDbConnection( _ "PROVIDER=Microsoft.Jet.OLEDB.4.0;" _ & "DATA SOURCE=" _ & Server.MapPath _ ("ContactDB.mdb;")) DBAdd.CommandText = "Insert Into Contacts " _ & "(ContactName, ContactEmail, Topic, " _ & "TheMessage, DateTimeEntered) values (" _ & "'" & Replace(txtContactName.Text, "'", "''") _ & "', " _ & "'" & Replace(txtContactEmail.Text, "'", "''") _ & "', " _ & "'" & ddlTopic.SelectedItem.Text & "', " _ & "'" & Replace(txtTheMessage.Text, "'", "''") _ & "', Now)" DBAdd.Connection = DBConn DBAdd.Connection.Open DBAdd.ExecuteNonQuery() lblMessage.Text = "Your request has been submitted." End Sub </SCRIPT> <HTML> <HEAD> <TITLE>Contact Us Page</TITLE> </HEAD> <form runat="server"> <asp:Label id="lblMessage" Font-Size="12pt" Font-Name="Tahoma" runat="server" Text="Complete each field to submit your communication." /> <P></P><Font Face="Tahoma">Your Name:</Font><BR> <asp:textbox id="txtContactName" columns="25" maxlength="50" runat=server /> <asp:requiredfieldvalidator id="rfvContactName" controltovalidate="txtContactName" display="Dynamic" font-name="Tahoma" font-size="10pt" runat=server> User Name is Required! </asp:RequiredFieldValidator> <P></P><Font Face="Tahoma">Your Email:</Font><BR> <asp:textbox id="txtContactEmail" columns="25" maxlength="50" runat=server /> <asp:requiredfieldvalidator id="rfvContactEmail" controltovalidate="txtContactEmail" display="Dynamic" font-name="Tahoma" font-size="10pt" runat=server> User Name is Required! </asp:RequiredFieldValidator> <P></P><Font Face="Tahoma">Select Topic:</Font><BR> <asp:dropdownlist id="ddlTopic" runat=server > <asp:listitem>Web Site</asp:listitem> <asp:listitem>Order Status</asp:listitem> <asp:listitem>Other</asp:listitem> </asp:dropdownlist> <P></P><Font Face="Tahoma">Your Message:</Font><BR> <asp:textbox id="txtTheMessage" columns="25" rows=5 textmode="multiline" runat=server /> <BR><BR> <asp:button id="butOK" text=" OK " OnClick="SubmitBtn_Click" runat="server" /> </form> </BODY> </HTML>
Address form Demo (VB.net)
<%-- Code revised from ASP.NET Tips & Techniques (Paperback) by Greg Buczek # Publisher: McGraw-Hill/Osborne Media; 1st edition (May 21, 2002) # Language: English # ISBN: 0072225149 --%> <%@ Page Language=VB Debug=true %> <%@ Import Namespace="System.Data" %> <%@ Import Namespace="System.Data.OLEDB" %> <script runat=server> Sub Page_Load(ByVal Sender as Object, ByVal E as EventArgs) If Not IsPostBack Then Dim DBConn as OleDbConnection Dim DBCommand As OleDbDataAdapter Dim DSPageData as New DataSet DBConn = New OleDbConnection( _ "PROVIDER=Microsoft.Jet.OLEDB.4.0;" _ & "DATA SOURCE=" _ & Server.MapPath _ ("StoresDB.mdb;")) DBCommand = New OleDbDataAdapter _ ("Select Distinct State From Stores " _ & "Order By State", DBConn) DBCommand.Fill(DSPageData, _ "States") ddlStates.DataSource = _ DSPageData.Tables("States").DefaultView ddlStates.DataBind() End If End Sub Sub ddlState_Changed(Sender As Object, E As EventArgs) Dim DBConn as OleDbConnection Dim DBCommand As OleDbDataAdapter Dim DSPageData as New DataSet DBConn = New OleDbConnection( _ "PROVIDER=Microsoft.Jet.OLEDB.4.0;" _ & "DATA SOURCE=" _ & Server.MapPath _ ("StoresDB.mdb;")) DBCommand = New OleDbDataAdapter _ ("Select Distinct City From Stores " _ & "Where State = '" & ddlStates.SelectedItem.Text _ & "' Order By City", DBConn) DBCommand.Fill(DSPageData, _ "Cities") ddlCities.DataSource = _ DSPageData.Tables("Cities").DefaultView ddlCities.DataBind() ddlCities.Visible = True lblMessage3.Visible = True End Sub Sub ddlCity_Changed(Sender As Object, E As EventArgs) Dim DBConn as OleDbConnection Dim DBCommand As OleDbDataAdapter Dim DSPageData as New DataSet DBConn = New OleDbConnection( _ "PROVIDER=Microsoft.Jet.OLEDB.4.0;" _ & "DATA SOURCE=" _ & Server.MapPath _ ("StoresDB.mdb;")) DBCommand = New OleDbDataAdapter _ ("Select StoreName as [Store Name], " _ & "Address From Stores " _ & "Where City = '" _ & ddlCities.SelectedItem.Text & "' " _ & "And State = '" _ & ddlStates.SelectedItem.Text & "' " _ & "Order By StoreName", DBConn) DBCommand.Fill(DSPageData, _ "Stores") dgStores.DataSource = _ DSPageData.Tables("Stores").DefaultView dgStores.DataBind() End Sub </SCRIPT> <HTML> <HEAD> <TITLE>Store Location</TITLE> </HEAD> <Body LEFTMARGIN="40"> <form runat="server"> <BR><BR> <asp:label id="lblMessage2" font-size="10pt" font-name="Lucida Console" text="Select a State" runat="server" /> <BR> <asp:dropdownlist id="ddlStates" datatextfield="State" autopostback="True" onselectedindexchanged="ddlState_Changed" runat="server" /> <BR><BR> <asp:label id="lblMessage3" font-size="10pt" font-name="Lucida Console" text="Select a City" visible="False" runat="server" /> <BR> <asp:dropdownlist id="ddlCities" datatextfield="City" autopostback="True" onselectedindexchanged="ddlCity_Changed" visible="False" runat="server" /> <BR><BR> <asp:label id="lblMessage1" font-size="12pt" font-bold="True" font-name="Lucida Console" text="Stores in Your Area" runat="server" /> <BR><BR> <asp:datagrid id="dgStores" runat="server" autogeneratecolumns="True" /> </form> </BODY> </HTML>