i have a code that i want it to add dates on the database but when i execute the code it says
Object reference not set to an instance of an object.
here is my jquery calender control
<head>
<meta charset="utf-8" />
<title>jQuery UI Datepicker - Default functionality</title>
<link rel="stylesheet" href="http://code.jquery.com/ui/1.10.3/themes/smoothness/jquery-ui.css" />
<script src="http://code.jquery.com/jquery-1.9.1.js"></script>
<script src="http://code.jquery.com/ui/1.10.3/jquery-ui.js"></script>
<link rel="stylesheet" href="/resources/demos/style.css" />
<script>
$(document).ready(function () {
<%-- Dates for election--%>
$("#dt1").datepicker({
dateFormat: "dd-M-yy",
minDate: 0,
onSelect: function (date) {
var date2 = $('#dt1').datepicker('getDate');
date2.setDate(date2.getDate() + 1);
$('#dt2').datepicker('setDate', date2);
$('#dt2').datepicker('option', 'minDate', date2);
}
});
$('#dt2').datepicker({
dateFormat: "dd-M-yy",
minDate: 1,
onClose: function () {
var dt1 = $('#dt1').datepicker('getDate');
var dt2 = $('#dt2').datepicker('getDate');
if (dt2 <= dt1) {
var minDate = $('#dt2').datepicker('option', 'minDate');
$('#dt2').datepicker('setDate', minDate);
}
}
});
<%-- Dates for Party--%>
$("#pt1").datepicker({
dateFormat: "dd-M-yy",
minDate: 0,
onSelect: function (date) {
var date2 = $('#pt1').datepicker('getDate');
date2.setDate(date2.getDate() + 1);
$('#pt2').datepicker('setDate', date2);
$('#pt2').datepicker('option', 'minDate', date2);
}
});
$('#pt2').datepicker({
dateFormat: "dd-M-yy",
minDate: 1,
onClose: function () {
var dt1 = $('#pt1').datepicker('getDate');
var dt2 = $('#pt2').datepicker('getDate');
if (dt2 <= dt1) {
var minDate = $('#pt2').datepicker('option', 'minDate');
$('#pt2').datepicker('setDate', minDate);
}
}
});
});
</script>
</head>
<table border="0" cellpadding="2" style="width: 700px;">
<asp:Label ID="Label1" runat="server" ForeColor="Green" Text=""></asp:Label>
<tr>
<td style="color: #5D7B9D;" align="center">Election Name:</td>
<td>
<asp:TextBox ID="txtElectionName" AutoPostBack="true" runat="server" Style="color: #5D7B9D; width: 150px; border-color: #5D7B9D; border-width: 1px; border-style: Solid;"></asp:TextBox>
<asp:RequiredFieldValidator ID="RequiredFieldValidator1" ControlToValidate="txtElectionName" ForeColor="Red" runat="server" ErrorMessage="Please enter election name."></asp:RequiredFieldValidator>
</td>
</tr>
<%-- Election start date here --%>
<tr>
<td style="color: #5D7B9D;" align="center">Election Start Date:</td>
<td>
<input type="text" id="dt1" />
</td>
</tr>
<tr>
<td style="color: #5D7B9D;" align="center">Election End Date:</td>
<td>
<input type="text" id="dt2" />
</td>
</tr>
<tr>
<td style="color: #5D7B9D;" align="center">Adding a Party Start Date:</td>
<td>
<input type="text" id="pt1" />
</td>
</tr>
<tr>
<td style="color: #5D7B9D;" align="center">Adding a Party End Date:</td>
<td>
<input type="text" id="pt2" />
</td>
</tr>
<tr>
<td align="right">
<br />
<asp:Label ID="lblResults" runat="server" Text=""></asp:Label>
<asp:Button ID="AddElection" runat="server" Text="Submit" OnClick="AddElection_Click" Style="color: white; width: 100px; background-color: #284775; border-color: #5D7B9D; border-width: 1px; border-style: Solid;" />
</td>
</tr>
</table>
Here is my code behind
protected void AddElection_Click(object sender, EventArgs e)
{
string estart = Request.Form["dt1"];
string eend = Request.Form["dt2"];
string pstart = Request.Form["pt1"];
string pend = Request.Form["pt2"];
NewElection elec = new NewElection(txtElectionName.Text, Request["estart"].ToString(), Request["eend"].ToString(), Request["pstart"].ToString(), Request["pend"].ToString());
elections.AddElections(elec);
Label1.Text = "Thank you for adding an election.";
}