This is for a simple web UI. A form that allows the user to create a new marker. It worked with Validation yesterday, but appears to have stopped today. It now throws a NullReferenceException at a certain point. Commenting out the reference moves the exception back in the file.
Definy bits
const string sDateTimeFormat = "dd-MM-yyyy HH:mm:ss";
DateTime dtStartPeriod = DateTime.MinValue;
DateTime dtEndPeriod = DateTime.MinValue;
DateTime createDate = DateTime.Now;
string cellNumber1 = null;
string cellNumber2 = null;
string cellNumber3 = null;
if (int.TryParse(Request.Form["vehicleId"], out value))
{
vehicleId = value;
}
else
{
vehicleId = -1;
}
Validation.Add("vehicleId",
Validator.Integer("You must choose a valid vehicle"),
Validator.Required("You must choose a vehicle from the list"),
Validator.Range(1000, 9999, "Pick a vehicle from the list provided")
);
Validation.Add("startDate",
Validator.DateTime(),
Validator.Required("Start date is a required field"),
Validator.StringLength(19, 19, "Start date's format is " + sDateTimeFormat + " and is 19 characters long")
);
Validation.Add("endDate",
Validator.DateTime(),
Validator.Required("End date is a required field"),
Validator.StringLength(19, 19, "End date's format is " + sDateTimeFormat + " and is 19 characters long")
);
Html form elements
<fieldset name="startDateFieldSet">
<label for="startDateControl">Pick Start Date</label>
<input type="datetime"
name="startDate"
id="startDateControl"
class="@Validation.ClassFor("startDate")"
value="@((dtStartPeriod == DateTime.MinValue) ? "" : dtStartPeriod.ToString(sDateTimeFormat))" />
@Html.ValidationMessage("startDate")
<br /><span class="requiredFormat">@sDateTimeFormat</span>
</fieldset>
<fieldset name="endDateFieldSet">
<label for="endDateControl">Pick End Date</label>
<input type="datetime"
name="endDate"
id="endDateControl"
class="@Validation.ClassFor("endDate")"
value="@((dtEndPeriod == DateTime.MinValue) ? "" : dtEndPeriod.ToString(sDateTimeFormat))" />
@Html.ValidationMessage("endDate")
<br /><span class="requiredFormat">@sDateTimeFormat</span>
</fieldset>
Screenshots
screenshot 1 http://www.ctrackonline.com.au/screenshots/anchor-1.jpg
screenshot 2 http://www.ctrackonline.com.au/screenshots/anchor-2.jpg
screenshot 3 http://www.ctrackonline.com.au/screenshots/anchor-3.jpg
screenshot 4 http://www.ctrackonline.com.au/screenshots/anchor-4.jpg
Is it due to your @cellNumber1.ToString?