Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

Troubleshooting
Research
Professional Opinions
Ask a Question
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE

troubleshooting Question

SharePoint DatePicker Default Value

Avatar of GerryOSullivan
GerryOSullivan asked on
Microsoft SharePointMicrosoft Server Apps
4 Comments1 Solution5303 ViewsLast Modified:
Hello,

I am having an issue with setting the default date into a date picker control on a custom SharePoint .aspx page.

My code is below but the part in the OnLoad event where I set the datepicker value causes an unknown error to appear.

Thanks for any help.
<script runat="server">
    
private const string webAppPropertyKey = "Custom404Path";
 
protected override void OnLoad(EventArgs e)
{
    using (SPWeb site = SPContext.Current.Site.OpenWeb())
    {
        //****************************************
        // Validate the page request to avoid
        // any malicious posts
        if (Request.HttpMethod == "POST")
            SPUtility.ValidateFormDigest();
 
        //****************************************
        // Get a reference the roles that are
        // bound to the user and the role
        // definition to which we need to verify
        // the user against
        SPRoleDefinitionBindingCollection usersRoles = site.AllRolesForCurrentUser;
        SPRoleDefinitionCollection siteRoleCollection = site.RoleDefinitions;
        SPRoleDefinition roleDefinition = siteRoleCollection["Contribute"];
 
        //Check if the user is in the role
        if ((usersRoles.Contains(roleDefinition)) || site.CurrentUser.IsSiteAdmin)
        {
            //*******************************
            //Check if post back to run
            //code that initiates the page
            if (IsPostBack != true)
            {
                InitPage();
                //initialise the datepicker
               dteScheduleSTARTMeeting.SelectedDate = DateTime.Today();
            }
        }
        else
        {
            Response.Redirect("/_layouts/accessdenied.aspx");
        }
    }
}
 
//*********************************************
// This method populates the listbox with
// all of the lists(SPList) in the site(SPWeb)
public void InitPage()
{
    //Get a reference to the SPWeb object
    using (SPWeb site = SPContext.Current.Site.OpenWeb())
    {
       
       
    }
}
   
public void Copy(object sender, System.EventArgs e)
{
    SPWeb oWeb = SPContext.Current.Web;
 
    SPList oList = oWeb.Lists[new Guid(Context.Request["List"])];
    SPListItem oItem = oList.GetItemById(int.Parse(Context.Request["ID"]));
 
    SPListItem oNewItem = oList.Items.Add();
 
    foreach (SPField oField in oItem.Fields)
    {
        if (!oField.ReadOnlyField &&
            oField.InternalName != "ContentType" &&
            oField.Type != SPFieldType.Invalid &&
            oField.Type != SPFieldType.WorkflowStatus &&
            oField.Type != SPFieldType.File &&
            oField.Type != SPFieldType.Computed &&
            oField.Type != SPFieldType.Lookup)
        {
            oNewItem[oField.Id] = oItem[oField.Id];
            oNewItem["Meeting_x0020_Date"] = dteScheduleSTARTMeeting.SelectedDate;
        }
    }
   
   
    oWeb.AllowUnsafeUpdates = true;
    oNewItem.Update();
 
    Context.Response.Redirect(oWeb.Url + "/" + oList.RootFolder.Url);
}   
 
</script> 
 
<asp:Content ID="Main" runat="server" contentplaceholderid="PlaceHolderMain" >
<br /><br />
<table style="font-size:8pt" cellspacing="20">
    <tr>
        <td valign="top">
            <b>Enter Meeting Date:</b><br /><br />
            <SharePoint:DateTimeControl ID="dteScheduleSTARTMeeting" runat="server" DateOnly="true" LocaleId="6153" /> 
                <asp:CompareValidator id="valSTARTDate" runat="server" ForeColor="Red"
                ControlToValidate="dteScheduleSTARTMeeting$dteScheduleSTARTMeetingDate" Type="Date" Operator="DataTypeCheck" 
                ErrorMessage="Please enter a valid Meeting date" />
        </td>
    </tr> 
    <tr>
        <td valign="top">     
            <asp:Button ID="btnCopy" runat="server" Text="Copy" Enabled="true" OnClick="Copy" />
        </td>
    </tr>
</table>
<br />
<br />
<asp:Label ID="litMessage" runat="server"/>
</asp:Content>
 
<asp:Content ID="PageTitle" runat="server" contentplaceholderid="PlaceHolderPageTitle" >
    Copy List Item
</asp:Content>
 
<asp:Content ID="PageTitleInTitleArea" runat="server" contentplaceholderid="PlaceHolderPageTitleInTitleArea" >
    Copy List Item
</asp:Content>
ASKER CERTIFIED SOLUTION
Avatar of 66866
Commented:
This problem has been solved!
Unlock 1 Answer and 4 Comments.
See Answers