Problem in accessing the usercontol properties
Hi,
I am Anuj Rathi. I m facing a problem with usercontrol. I m not able to access the properties that are defined in usercontrol.
My prob is:
I hav a userControl in which i hav placed 3 DropDownListBox or (these can be listboxes), for hours(0-12), Minutes(0-60) & AM/PM. & write the properties in .ascx.cs for accessing the values in my .aspx web page.
in the page load event of the user control, i hav written
if(! IsPostBack)
{
for(int i=0;i<=12;i++)
{
if(i<=9)
ddlHours.Items.Add(new ListItem("0" + i));
else
ddlHours.Items.Add(new ListItem(Convert.ToString(i)));
}
}
& define the properties as follows:
public string Hours
{
get
{
return ddlHours.SelectedItem.ToString();
}
}
I hav also import the UserControl's namespace, in the aspx page.
But when i m trying to access the value of the ddlHours in my page with button's click event:
DateTimePicker dtp = new DateTimePicker(); // Create object
Response.Write(dtp.Hours);
It gives an error
"Object reference not set to an instance of an object"
pls give me a proper solution.!!!!!!!
|