Australian Election Day Polling Place Stall Finder
A tradition at every Australian election polling place is a variety of stalls with cakes, arts and crafts, and sausage sizzles. During my lunch break today I designed a simple web application using ASP.NET and a little AJAX that will let you search for a polling place and see what stall are available. Most stalls have a fundraising focus so it allows them to promote their stall online. The link is http://www.castnerit.com/polling-booth-stall-finder/
Student Position available at Castner IT
Castner IT is an IT consulting firm that provides business system analysis, web development, and intranet development services to companies in Australia and the United States. We offer services across the full development lifecycle and develop systems using ASP.NET, C#, SharePoint, and SQL Server.
We currently have a position opening for a suitably qualified person to assist on a number of projects on a casual contract basis. The amount of work will average 1-2 days a week and would ideally suit a student studying information technology or information systems looking to gain industry experience and a willingness to learn.
The job role involves the following tasks:
- Assisting with the setup of online courses (including uploading files, entering survey and quiz questions, writing course and subject summaries)
- Assisting with the writing of user manuals and tutorials for a company intranet
- Assisting with development of PowerPoint slides on small business use of the Internet
- Assisting with development of ASP.NET/C#/SQL Server web applications
Required Skills
- Web page development
- Microsoft Office 2007/2010 (Word and PowerPoint)
- Excellent written communication skills
- Ability to work unsupervised
- Proactive attitude
Bonus Skills – one or more of these skills would be great but we will provide training if you don’t have them.
- ASP.NET application development
- Experience with online learning systems such as Blackboard or Moodle
- Experience with content management systems such as SharePoint or Joomla
- Please email enquiries@castnerit.com with your cv and a cover letter addressing the job role and required skills.
Job Posted: 4 August 2010
Position closes: 18 August 2010
Avoiding ASP.NET dropdownlist has a selectedvalue which is invalid exceptions
It is often to difficult to capture the following ASP.NET dropdownlist error when the dropdownlist is bound to an sqldatasource:
Dropdownlistname has a SelectedValue which is invalid because it does not exist in the list of items
This exception is frequently caused by poor validation controls during data entry and/or poor database design. For example, the previous application might have allowed invalid data combinations. In an ideal world, you would fix the validation controls or database design before data entry commenced but often (as in my case on a recent project) you have inherited a database where invalid data was allowed to slip through.
Once you fix the application by introducing appropriate validation controls, when users go to edit the records with invalid data, they start to receive a range of exceptions including dropdownlist selectedvalue errors. It is reasonably difficult to catch these exceptions at runtime. There are a number of solutions including:
- Cleaning the data
- Adding the missing value to the database table that is the datasource for the dropdownlist.
- Catching the exception from the ondatabind event of the dropdownlist by adding an eventhandler (see for example dynadata’s post at http://forums.asp.net/t/937399.aspx?PageIndex=2).
Cleaning the data would be a good solution but not always possible. Adding the missing value is a quick solution but it may introduce more invalid data into the database and often the missing “value” is null or blank which ideally you want to avoid adding. Catching the error on databind is a good solution but requires changing the out of range selected value to a default value before the dropdownlist is rendered. If you are using this approach, you should warn the user that the data has been changed and display the invalid value so that the user can make note of the previous value before updating the data.
One alternative solution that I am exploring that doesn’t require the selected value to be changed beforehand is to rewrite the sqldatasource SELECT statement for the dropdownlist in the edit template of a formview (or other control) while leaving the insert template statement with only the valid list items. The rewritten SELECT statement for the dropdownlist sqldatasource includes a UNION operator. The second SELECT statement includes the invalid value or values. It has the benefit of not having to add the invalid records into the database and the data does not have to be changed before rendering the dropdownlist. Users could then be warned that the data is invalid and be asked (or forced) to change it to a valid value before updating the database.
Examples:
SELECT F1, F2 FROM Table1 UNION SELECT ” AS F3, ” AS F4 FROM Table1 AS T1 ORDER BY F1
SELECT F1, F2 FROM Table1 UNION SELECT NULL AS F3, ” AS F4 FROM Table1 AS T1 ORDER BY F1
The first example handles a blank value as the selected value, the second example handles null being the selected value.
Any constructive feedback on the alternative approaches is welcome.
Consuming a web service using ASP.NET
This is a video tutorial I created for my eBusiness class at the University of Oregon. It is an introduction to consuming a web service and using the Google Maps API with ASP.NET and Visual Studio 2008. It highlights how to create and use a web reference on an ASP.NET web page with Visual Basic. It also provides an example on how to use the RegisterStartupScript method to insert JavaScript using Visual Basic.
For more information on location-based services, contact the experienced staff at Castner IT
YouTube Link: http://www.youtube.com/watch?v=iD8WwKwc0nI
Replying from mail-enabled public folder as public folder’s email address
When you create a mail-enabled public folder in Microsoft Exchange/Outlook, the default is for any email sent from the public folder to come from the individual’s and not the publc folder’s email address. This Outlook 2007 add-on fixes that problem by changing the from address to the public folder’s address and also bcc’ing the public folder so that it retains a copy for any sent items. Finally, it inserts a public folder signature.
The following code requires some customization (see references in code below):
- You need to create a C# case for each public folder.
- You need to enter your signature text.
Limitations:
- The same signature for all public folders
Requirements
- Appropriate Send As permissions on the public folders
Code for ThisAddIn.cs:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml.Linq;
using Outlook = Microsoft.Office.Interop.Outlook;
using OutlookEvents = Microsoft.Office.Interop.Outlook.ItemEvents_10_Event;
using Office = Microsoft.Office.Core;
using System.Windows.Forms;
using System.Windows.Controls;
using System.Windows;
using Microsoft.Office.Interop.Outlook;
using System.Runtime.InteropServices;
using System.Security;
using System.Security.Principal;
using System.Threading;
namespace MyPublicFolder
{
public partial class ThisAddIn
{
MailItem _mailItem = null;
Office.CommandBar newToolBar;
Office.CommandBarButton firstButton;
Office.CommandBarButton secondButton;
Office.CommandBarButton thirdButton;
Outlook.Explorers selectExplorers;
string strName;
string mysignature;
string p_pfEmailAddress = insert default email address// Method for AddIn Startup
private void ThisAddIn_Startup(object sender, System.EventArgs e)
{
this.Application.ItemLoad += new ApplicationEvents_11_ItemLoadEventHandler(Application_ItemLoad);
selectExplorers = this.Application.Explorers;
selectExplorers.NewExplorer += new Outlook.ExplorersEvents_NewExplorerEventHandler(newExplorer_Event);
AddToolbar();
} // Currently not used
private void ThisAddIn_Shutdown(object sender, System.EventArgs e)
{
}
// Run for each mail item loaded
void Application_ItemLoad(object Item)
{
if (Item is MailItem)
{
try
{
MailItem mailItem = Item as MailItem;
((Outlook.ItemEvents_10_Event)mailItem).Reply += new ItemEvents_10_ReplyEventHandler(mailItem_Reply);
mailItem.Open += new ItemEvents_10_OpenEventHandler(mailItem_Open);
_mailItem = mailItem;
}
catch (System.Exception ex)
{
System.Windows.Forms.MessageBox.Show(ex.ToString(), "Exception", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
}
// Method when public folder mail item is opened
void mailItem_Open(ref bool Cancel)
{
Explorer myExplorer = Application.ActiveExplorer();
Inspector myInspector = Application.ActiveInspector();
string myFolder;
myFolder = myExplorer.CurrentFolder.Name;
try
{
switch (myFolder)
{
case “Insert Public Folder 1 Name”:
setpfproperties(“PublicFolder1 email address”);
p_pfEmailAddress = ” PublicFolder1 email address”;
break;
case “Insert Public Folder 2 Name”:
setpfproperties(“PublicFolder2 email address”);
p_pfEmailAddress = “PublicFolder2 email address”;
break;
}
}
catch (System.Exception ex)
{
System.Windows.Forms.MessageBox.Show(“Error. Email will not be sent from public folder. Please manually set the from address. Details: ” + ex.Message);
}
}
// Method to set from and bcc addresses for public folders
void setpfproperties(string pfaddress)
{
_mailItem.SentOnBehalfOfName = pfaddress;
_mailItem.BCC = pfaddress;
}
// Run the add toolbar sub when Outlook activates
private void newExplorer_Event(Outlook.Explorer new_Explorer)
{
((Outlook._Explorer)new_Explorer).Activate();
newToolBar = null;
AddToolbar();
}
// Create a new toolbar for public folders
private void AddToolbar()
{
if (newToolBar == null)
{
Office.CommandBars cmdBars = this.Application.ActiveExplorer().CommandBars;
newToolBar = cmdBars.Add(“NewToolBar”, Office.MsoBarPosition.msoBarTop, false, true);
}
try
{
Office.CommandBarButton button_1 = (Office.CommandBarButton)newToolBar.Controls.Add(1, missing, missing, missing, missing);
button_1.Style = Office.MsoButtonStyle.msoButtonCaption;
button_1.Caption = “New Public Folder Message”;
button_1.Tag = “New Public Folder Message”;
if (this.firstButton == null)
{
this.firstButton = button_1;
firstButton.Click += new Office._CommandBarButtonEvents_ClickEventHandler(ButtonNewClick);
}
// Reply Button
Office.CommandBarButton button_2 = (Office.CommandBarButton)newToolBar.Controls.Add(1, missing, missing, missing, missing);
button_2.Style = Office.MsoButtonStyle.msoButtonCaption;
button_2.Caption = “Reply to Public Folder Message”;
button_2.Tag = “Reply to Public Folder Message”;
if (this.secondButton == null)
{
this.secondButton = button_2;
secondButton.Click += new Office._CommandBarButtonEvents_ClickEventHandler(ButtonReplyClick);
}
Office.CommandBarButton button_3 = (Office.CommandBarButton)newToolBar.Controls.Add(1, missing, missing, missing, missing);
button_3.Style = Office.MsoButtonStyle.msoButtonCaption;
button_3.Caption = “Internal Reply to Public Folder Message”;
button_3.Tag = “Internal Reply to Public Folder Message”;
if (this.thirdButton == null)
{
this.thirdButton = button_3;
thirdButton.Click += new Office._CommandBarButtonEvents_ClickEventHandler(ButtonInternalReplyClick);
}
newToolBar.Visible = true;
}
catch (System.Exception ex)
{
System.Windows.Forms.MessageBox.Show(ex.Message);
}
}
// Method for Reply Toolbar Button
private void ButtonReplyClick(Office.CommandBarButton ctrl, ref bool cancel)
{
Outlook.MailItem myItem;
try
{
Outlook.MailItem msg = Application.ActiveExplorer().Selection[1] as Outlook.MailItem;
if (msg != null)
{
mysignature = “insert signature line 1″;
mysignature += “insert signature line 2 etc”;
myItem = ((Outlook._MailItem)msg).Reply();
myItem.HTMLBody = mysignature + myItem.HTMLBody;
myItem.Display(false);
}
else
{
System.Windows.Forms.MessageBox.Show(“No email message selected”);
}
}
catch (System.Exception ex)
{
System.Windows.Forms.MessageBox.Show(ex.Message);
}
}
#region VSTO generated code
///
/// Required method for Designer support – do not modify
/// the contents of this method with the code editor.
///
private void InternalStartup()
{
this.Startup += new System.EventHandler(ThisAddIn_Startup);
this.Shutdown += new System.EventHandler(ThisAddIn_Shutdown);
}
#endregion
}
}
Introduction to Expression Web
This tutorial is for people starting out with Microsoft Expression Web 2. It is aimed at users that have never used Expression Web or any other web development software. I originally created it for one of my classes at the University of Oregon. The tutorial covers how to create your first page, how to upload that page to a web server using FrontPage Server Extensions, how to do basic formatting, how to add a title and meta tags, and how to insert an image. I will be adding more tutorials soon that cover CSS and ASP.NET. Please follow the link below.
Tutorial – Introduction to Microsoft Expression Web
Inserting a PayPal Buy Now Button into an ASP.NET Form
When working with ASP.NET pages, one difficulty that often arises is that you need two forms on the page – the normal form required by ASP.NET and a second form for something else such as a PayPal button or a search tool. The solution that I discovered is to not have two forms but simply have one form (the normal one in the master page). It usually only requires some minor changes to the controls in the 2nd form for it to work. For example, here is the adjusted code for a PayPal Buy Now button:
<input type=”hidden” name=”cmd” value=”_xclick” />
<input type=”hidden” name=”business” value=”gcastner@asianfoods.com” />
<input type=”hidden” name=”item_name” value=”Sweet and sour sauce”/>
<input type=”hidden” name=”item_number” value=”SAUCE001″ />
<input type=”hidden” name=”amount” value=”100.00″ />
<input type=”hidden” name=”no_shipping” value=”2″ />
<input type=”hidden” name=”no_note” value=”1″ />
<input type=”hidden” name=”currency_code” value=”USD” />
<input type=”hidden” name=”lc” value=”US” />
<input type=”hidden” name=”bn” value=”PP-BuyNowBF” />
<img alt=”" style=’border:0px;’ src=’https://www.sandbox.paypal.com/en_US/i/scr/pixel.gif” width=”1″ height=”1″ />
<asp:Button ID=”Button2″ runat=”server” Text=”Button” PostBackUrl=”https://www.sandbox.paypal.com/cgi-bin/webscr” />
The main changes from the PayPal supplied code are the removal of the form tags and the inclusion of the asp:button. The reason for the change is that because ASP.NET pages are already web forms, we cannot simply add a 2nd form into the page (it would cause an error).
Another useful thing is that you can set the default button for the page, or different parts of the page. This example sets the default button when someone presses enter to the login button rather than the search button at the top of the page. You need to enclose the relevant controls in a panel control.
Protected Sub panelLogin_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles panelLogin.Load
Page.Form.DefaultFocus = Login1.FindControl(“UserName”).UniqueID
Page.Form.DefaultButton = Login1.FindControl(“LoginButton”).UniqueID
End Sub
Changing default language in Office 2007
I recently moved back to Australia from the USA and had plenty of fun
trying to change all of my defaults from USA to Australia. Here is a list of things to check whenever you are changing countries:
1. Microsoft Vista: Control Panel –> Clock, Language, and Region –> Change the country or region
and Control Panel –> Clock, Language, and Region –> Change the date, time, or number format
2. Time Zone: Click on the time –> Change Time Zone
3. For Microsoft Office 2007: All Programs –> Microsoft Office –> Microsoft Office Tools –> Microsoft Office 2007 Language
Microsoft reporting: Failed to enable constraints. One or more rows contain values violating non-null, unique, or foreign-key constraints.
This error was bugging
me for a long time until I found this excellent forum discussion:
http://forums.microsoft.com/MSDN/ShowPost.aspx?PostID=541116&SiteId=1
The following points summarize the causes and solutions from the forum and offer some additional help:
1. Check if you have changed the length of any fields in the underlying database table after creating the dataset. If you have, you may need to manually change them in the dataset as well. If you are using Visual Studio 2008, open the xsd file and click on the relevant field name. Ensure the maxlength property matches your new field length.
2. If you base your dataset off a view rather than a table, and that view contains a primary key field from the underlying table, visual studio may set unique to true for that field. If your view is constructed in such a way that the field is not unique, then the error will occur. In Visual Studio 2008, open the xsd file, click on the field and set unique to false in properties.
There were other causes of the error but these seemed to be the two most common.
Cheers,
Grant
A better way of handling maxRequestLength exceptions
ASP.NET 2 includes the FileUpload control to make it easier to create pages that allow users to upload files. The default maximum file size is 4096 KB to minimize the potential for denial of service attacks. You can change the maximum file size by editing your configuration files (see for example http://msdn2.microsoft.com/en-US/library/system.web.configuration.httpruntimesection.maxrequestlength(VS.80).aspx and http://support.softartisans.com/kbview_825.aspx).
The problem is that when users attempt to upload a file that is too large, it is difficult to capture and handle the exception that is created. The usual try..catch doesn’t handle the exception because the exception occurs before then. The exception is “System.Web.HttpException: Maximum request length exceeded”. You could of course increase the maximum file size but that defeats the purpose of the limit in the first place.
Here is one solution for handling the exception that is at least nicer than the standard ASP.NET exception message:
1. Create a global.asax file. If you’re using Visual Studio 2005 it will set up a number of common subroutines for you. You need to use Sub Application_Error. Your code should look something like this:
<script runat=”server”>
Sub Application_Error(ByVal sender As Object, ByVal e As EventArgs)
Dim currentException As Exception
currentException = Server.GetLastError.GetBaseException()
Response.Redirect(“/error.aspx?Err=” & Server.UrlEncode(currentException.Message))
End Sub
</script>
The application_Error sub fires as a last resort, in other words, when you haven’t explicitly handled the exception anywhere else in your code.
2. You can now create an error.aspx that displays the exception message (from the querystring). For this exception the message is “Maximum request length exceeded”. You could also test for the message and give users more information on the error.
Please let me know if you have any comments, suggestions, or improvements.

