简体   繁体   中英

How to assign property for BasicDatePicker in asp.net c#?

I want to assign property for BasicDateTimePicker

I tried but it's getting null value

Code:

.ascx

<%@ Register Assembly="BasicFrame.WebControls.BasicDatePicker" Namespace="BasicFrame.WebControls" TagPrefix="dp" %>

<dp:BasicDatePicker ID="BasicDatePicker4" runat="server"></dp:BasicDatePicker>

.ascx.cs

Here I'm maintaing the values

protected void Page_Load(object sender, EventArgs e)
{
  txtUser.Text = Request.Form[txtUser.UniqueID];
  dropCountry.SelectedValue = Request.Form[dropCountry.UniqueID];
  dropEntry.SelectedValue = Request.Form[dropEntry.UniqueID];
  //Here I'm getting "Cannot implicitly conert type string to System.Date"
  BasicDatePicker4.SelectedDate = Request.Form[BasicDatePicker4.UniqueID];
}

I tried to assign the property but it's not working

    public string ExpiryDate
    {
        get
        {
            return BasicDatePicker4.SelectedDate.ToString();
        }
        set
        {
            BasicDatePicker4.SelectedDate = DateTime.Today;
        }
    }

Any ideas? Thanks in advance

You never assign something to ExpiryDate, the setter of the property will only be called when you call

ExpiryDate = DateTime.Today

also change your setter to use value instead of a hardcoded date, and change the Type of your property to DateTime as the picker only excepts a DateTime

public DateTime ExpiryDate
{
    get
    {
        return BasicDatePicker4.SelectedDate;
    }
    set
    {
        BasicDatePicker4.SelectedDate = value;
    }
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM