locked
CalendarExtender not working in DateTime Edit Field Template RRS feed

  • Question

  • User-1759624489 posted

     

    Hello. All I am using ajax with dynamic data futures.

     


        public class ContractMetaData
        {
            public object ContractId { get; set; }

            [DisplayName("Fecha Inicio Contrato")]
            [Required(ErrorMessage = "Este campo es Requerido")]
            [UIHint("DateTime")]   
            public object StartDate { get; set; }

            [DisplayName("Fecha Fin Contrato")]
            [Required(ErrorMessage = "Este campo es Requerido")]
            [UIHint("DateTime")]   
            public object EndDate { get; set; }

     

     

    <asp:TextBox ID="TextBox1" runat="server" CssClass="droplist" Text='<%# FieldValueEditString %>' Columns="20"></asp:TextBox>
    <asp:ImageButton ID="ImageButton1" runat="server"  src="logoParadigma.png" CausesValidation="false" />

    <cc1:CalendarExtender ID="CalendarExtender1" PopupButtonID="ImageButton1" runat="server" TargetControlID="TextBox1" >
    </cc1:CalendarExtender>

     

    When I click the image, the calendar does not show up.

     

    Any Idea??
    Tuesday, September 9, 2008 6:00 PM

All replies

  • User1641955678 posted

    The Futures app uses the AJAX calendar (see DateAjaxCalendar_Edit.ascx) and it works fine, so that shoul give you a starting point to get it working in your scenario.

    David

    Tuesday, September 9, 2008 8:31 PM
  • User-1759624489 posted

    I cant make it work.

    It doesnt show me any errors but it doesnt come up the calendar either.

     


            [DisplayName("Fecha Inicio Contrato")]
            [Required(ErrorMessage = "Este campo es Requerido")]
            [UIHint("DateAjaxCalendar")]   
            public object StartDate { get; set; }

            [DisplayName("Fecha Fin Contrato")]
            [Required(ErrorMessage = "Este campo es Requerido")]
            [UIHint("DateAjaxCalendar")]   
            public object EndDate { get; set; }

     

     

     

    Wednesday, September 10, 2008 10:56 AM
  • User-1759624489 posted

    I havent been able to make it work

     

    Wednesday, September 10, 2008 11:39 AM
  • User-1759624489 posted

     I have tried everything, analyzed line by line I just dont know what happens.

     

    Please tell me which code should I paste here, so we can more easily debug whats going on

     

    Thank y ou very much

    Wednesday, September 10, 2008 1:14 PM
  • User-330204900 posted

    Are you seeing an error shown in the status bar? If so you may need to disable Partial Rendering in the master page

    <asp:ScriptManager ID="ScriptManager1" runat="server" EnablePartialRendering="true"/>

    change to

    <asp:ScriptManager ID="ScriptManager1" runat="server" EnablePartialRendering="false"/>
    Wednesday, September 10, 2008 1:35 PM
  • User-1759624489 posted

     Hi. I cant disable it on the master page, but I tried disabling it by code.

     

     protected void Page_Init(object sender, EventArgs e) {
            DynamicDataManager1.RegisterControl(GridView1, true /*setSelectionFromUrl*/);
            DynamicDataManager1.RegisterControl(DetailsView1);
            table = GridDataSource.GetTable();
           
            FileHelper.DisablePartialRenderingForUpload(this, table);

           
        }


        public static void DisablePartialRenderingForUpload(Page page, MetaTable table)
        {
            foreach (var column in table.Columns)
            {
                // TODO this depends on the name of the field template, need to fix
                if (String.Equals(column.UIHint, "DBImage", StringComparison.OrdinalIgnoreCase)
                    || String.Equals(column.UIHint, "FileImage", StringComparison.OrdinalIgnoreCase))
                {
                    var sm = ScriptManager.GetCurrent(page);
                    if (sm != null)
                    {
                        sm.EnablePartialRendering = false;
                    }
                    break;
                }
            }
        }

    Wednesday, September 10, 2008 2:07 PM
  • User-1759624489 posted

    I added a sentence to the if

     

      public static void DisablePartialRenderingForUpload(Page page, MetaTable table)
        {
            foreach (var column in table.Columns)
            {
                // TODO this depends on the name of the field template, need to fix
                if (String.Equals(column.UIHint, "DBImage", StringComparison.OrdinalIgnoreCase)
                    || String.Equals(column.UIHint, "FileImage", StringComparison.OrdinalIgnoreCase)
                    || String.Equals(column.UIHint, "DateAjaxCalendar", StringComparison.OrdinalIgnoreCase)
                   
                    )
                {
                    var sm = ScriptManager.GetCurrent(page);
                    if (sm != null)
                    {
                        sm.EnablePartialRendering = false;
                    }
                    break;
                }
            }
        }

     

    But it still doesnt work

     

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using System.Web.DynamicData;
    using System.Xml.Linq;
    using System.Web;
    using System.Web.Security;
    using System.Data;
    using System.ComponentModel.DataAnnotations;
    using System.Web.UI;
    using System.Web.UI.WebControls;
    using System.ComponentModel;
    using Microsoft.Web.DynamicData;
    using Sodexo.Data;

    namespace Sodexo.Entities
    {
        [MetadataType(typeof(ContractMetaData))] 
        public partial class Contract
        {

        }

        [DisplayName("Contratos")]
        public class ContractMetaData
        {
            public object ContractId { get; set; }

            [DisplayName("Nombre")]
            [Required(ErrorMessage = "Este campo es Requerido")]
            public object Name { get; set; }

            [DisplayName("Descripcion")]
            [Required(ErrorMessage = "Este campo es Requerido")]
            public object Description { get; set; }

            [DisplayName("Fecha Inicio Contrato")]
            [Required(ErrorMessage = "Este campo es Requerido")]
            [DisplayFormat(DataFormatString = "{0:dd-MMM-yyyy}")]
            [UIHint("DateAjaxCalendar")]       
            public DateTime  StartDate { get; set; }

            [DisplayName("Fecha Fin Contrato")]
            [Required(ErrorMessage = "Este campo es Requerido")]
            [DisplayFormat(DataFormatString = "{0:dd-MMM-yyyy}")]
            [UIHint("DateAjaxCalendar")]
            public DateTime EndDate { get; set; }

            [DisplayName("Archivo PDF del Contrato")]
            [UIHint("FileImage")]
            [Required(ErrorMessage = "Este campo es Requerido")]
            public object DocumentPath { get; set; }

            [DisplayName("Activos del contrato")]
            public object ContractAssets { get; set; }

            [DisplayName("Proveedor")]
            public object Supplier { get; set; }


       
        }
    }

     

    <%@ Control Language="C#" CodeFile="DateAjaxCalendar_Edit.ascx.cs" Inherits="DateAjaxCalendar_EditField" %>
    <%@ Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" TagPrefix="cc1" %>

    <asp:TextBox ID="TextBox1" runat="server" Text='<%# FieldValueEditString %>' CssClass="droplist"></asp:TextBox>
    <cc1:CalendarExtender ID="defaultCalendarExtender"  Format="MMMM d, yyyy"
     runat="server" TargetControlID="TextBox1" />

    <asp:RequiredFieldValidator runat="server" ID="RequiredFieldValidator1" CssClass="droplist" ControlToValidate="TextBox1" Display="Dynamic" Enabled="false" />
    <asp:DynamicValidator runat="server" ID="DynamicValidator1" CssClass="droplist" ControlToValidate="TextBox1" Display="Dynamic" />

     

     

    using System;
    using System.Collections.Specialized;
    using System.Web.UI;


        public partial class DateAjaxCalendar_EditField : System.Web.DynamicData.FieldTemplateUserControl {
            protected void Page_Load(object sender, EventArgs e) {
                SetUpValidator(RequiredFieldValidator1);
                SetUpValidator(DynamicValidator1);
            }

            protected override void ExtractValues(IOrderedDictionary dictionary) {
                dictionary[Column.Name] = ConvertEditedValue(TextBox1.Text);
            }

            public override Control DataControl {
                get {
                    return TextBox1;
                }
            }
        }

     

     

     

     

    Wednesday, September 10, 2008 2:13 PM
  • User-1759624489 posted

     Slowly I am finding the problem

     

    I added random text in DateTime.ascx and AjaxDateTimeCalendar.

     

    tumama
    <asp:TextBox ID="TextBox1" runat="server" Text='<%# FieldValueEditString %>' CssClass="droplist"></asp:TextBox>
    <cc1:CalendarExtender ID="defaultCalendarExtender"  Format="MMMM d, yyyy"
     runat="server" TargetControlID="TextBox1" />

     

    I noticed that it was rendering the DateTimeUserControl not the AjaxDateTimeEdit

     

    It seems the UIHINT is not working

    Wednesday, September 10, 2008 2:27 PM
  • User660823006 posted

    This probably means that your partial class is not being picked up which could mean it is in the wrong namespace (if needs to be in the same namespace as your entity objects). A sure way to check this is to remove the partial keyword, it should cause a compile error. If it does not then your namespace is wrong or the name of the entity is wrong.

    Wednesday, September 10, 2008 2:35 PM
  • User-1759624489 posted

     After removing it:

     

    namespace Sodexo.Entities         
    {
        [MetadataType(typeof(ContractMetaData))] 
        public  class Contract
        {

        }

     

    Error    1    Missing partial modifier on declaration of type 'Sodexo.Entities.Contract'; another partial declaration of this type exists    D:\Luis\Sodexho\CDS Bancolombia\CdsBancolombia\CDSBancolombia\Data\Management\Contract.cs    20    BLDAC    19

     

    But if I go to the Model.dbml.designer.cs

     

    I checked very carefully and I see everything ok

     #pragma warning disable 1591
    //------------------------------------------------------------------------------
    // <auto-generated>
    //     This code was generated by a tool.
    //     Runtime Version:2.0.50727.3053
    //
    //     Changes to this file may cause incorrect behavior and will be lost if
    //     the code is regenerated.
    // </auto-generated>
    //------------------------------------------------------------------------------

    namespace Sodexo.Data
    {
     //blabla bla
    }
    namespace Sodexo.Entities
    {
        using System.Runtime.Serialization;
        using System.Data.Linq;
        using System.Data.Linq.Mapping;
        using System.ComponentModel;
        using System;
        
        

        
        [Table(Name="dbo.Contract")]
        [DataContract()]
        public partial class Contract : INotifyPropertyChanging, INotifyPropertyChanged
        {
            
            private static PropertyChangingEventArgs emptyChangingEventArgs = new PropertyChangingEventArgs(String.Empty);
            
            private int _ContractId;
            
            private string _Name;
            
            private string _Description;
            
            private System.DateTime _StartDate;
            
            private System.DateTime _EndDate;
            
            private string _DocumentPath;
            
            private int _SupplierId;
            
            private EntitySet<ContractAsset> _ContractAssets;
            
            private EntityRef<Supplier> _Supplier;
            
            private bool serializing;
            
        #region Extensibility Method Definitions
        partial void OnLoaded();
        partial void OnValidate(System.Data.Linq.ChangeAction action);
        partial void OnCreated();
        partial void OnContractIdChanging(int value);
        partial void OnContractIdChanged();
        partial void OnNameChanging(string value);
        partial void OnNameChanged();
        partial void OnDescriptionChanging(string value);
        partial void OnDescriptionChanged();
        partial void OnStartDateChanging(System.DateTime value);
        partial void OnStartDateChanged();
        partial void OnEndDateChanging(System.DateTime value);
        partial void OnEndDateChanged();
        partial void OnDocumentPathChanging(string value);
        partial void OnDocumentPathChanged();
        partial void OnSupplierIdChanging(int value);
        partial void OnSupplierIdChanged();
        #endregion
            
            public Contract()
            {
                this.Initialize();
            }
            
            [Column(Storage="_ContractId", AutoSync=AutoSync.OnInsert, DbType="Int NOT NULL IDENTITY", IsPrimaryKey=true, IsDbGenerated=true)]
            [DataMember(Order=1)]
            public int ContractId
            {
                get
                {
                    return this._ContractId;
                }
                set
                {
                    if ((this._ContractId != value))
                    {
                        this.OnContractIdChanging(value);
                        this.SendPropertyChanging();
                        this._ContractId = value;
                        this.SendPropertyChanged("ContractId");
                        this.OnContractIdChanged();
                    }
                }
            }
            
            [Column(Storage="_Name", DbType="NVarChar(100) NOT NULL", CanBeNull=false)]
            [DataMember(Order=2)]
            public string Name
            {
                get
                {
                    return this._Name;
                }
                set
                {
                    if ((this._Name != value))
                    {
                        this.OnNameChanging(value);
                        this.SendPropertyChanging();
                        this._Name = value;
                        this.SendPropertyChanged("Name");
                        this.OnNameChanged();
                    }
                }
            }
            
            [Column(Storage="_Description", DbType="NVarChar(MAX) NOT NULL", CanBeNull=false)]
            [DataMember(Order=3)]
            public string Description
            {
                get
                {
                    return this._Description;
                }
                set
                {
                    if ((this._Description != value))
                    {
                        this.OnDescriptionChanging(value);
                        this.SendPropertyChanging();
                        this._Description = value;
                        this.SendPropertyChanged("Description");
                        this.OnDescriptionChanged();
                    }
                }
            }
            
            [Column(Storage="_StartDate", DbType="DateTime NOT NULL")]
            [DataMember(Order=4)]
            public System.DateTime StartDate
            {
                get
                {
                    return this._StartDate;
                }
                set
                {
                    if ((this._StartDate != value))
                    {
                        this.OnStartDateChanging(value);
                        this.SendPropertyChanging();
                        this._StartDate = value;
                        this.SendPropertyChanged("StartDate");
                        this.OnStartDateChanged();
                    }
                }
            }
            
            [Column(Storage="_EndDate", DbType="DateTime NOT NULL")]
            [DataMember(Order=5)]
            public System.DateTime EndDate
            {
                get
                {
                    return this._EndDate;
                }
                set
                {
                    if ((this._EndDate != value))
                    {
                        this.OnEndDateChanging(value);
                        this.SendPropertyChanging();
                        this._EndDate = value;
                        this.SendPropertyChanged("EndDate");
                        this.OnEndDateChanged();
                    }
                }
            }
            
            [Column(Storage="_DocumentPath", DbType="NVarChar(MAX) NOT NULL", CanBeNull=false)]
            [DataMember(Order=6)]
            public string DocumentPath
            {
                get
                {
                    return this._DocumentPath;
                }
                set
                {
                    if ((this._DocumentPath != value))
                    {
                        this.OnDocumentPathChanging(value);
                        this.SendPropertyChanging();
                        this._DocumentPath = value;
                        this.SendPropertyChanged("DocumentPath");
                        this.OnDocumentPathChanged();
                    }
                }
            }
            
            [Column(Storage="_SupplierId", DbType="Int NOT NULL")]
            [DataMember(Order=7)]
            public int SupplierId
            {
                get
                {
                    return this._SupplierId;
                }
                set
                {
                    if ((this._SupplierId != value))
                    {
                        if (this._Supplier.HasLoadedOrAssignedValue)
                        {
                            throw new System.Data.Linq.ForeignKeyReferenceAlreadyHasValueException();
                        }
                        this.OnSupplierIdChanging(value);
                        this.SendPropertyChanging();
                        this._SupplierId = value;
                        this.SendPropertyChanged("SupplierId");
                        this.OnSupplierIdChanged();
                    }
                }
            }
            
            [Association(Name="Contract_ContractAsset", Storage="_ContractAssets", ThisKey="ContractId", OtherKey="ContractId")]
            [DataMember(Order=8, EmitDefaultValue=false)]
            public EntitySet<ContractAsset> ContractAssets
            {
                get
                {
                    if ((this.serializing
                                && (this._ContractAssets.HasLoadedOrAssignedValues == false)))
                    {
                        return null;
                    }
                    return this._ContractAssets;
                }
                set
                {
                    this._ContractAssets.Assign(value);
                }
            }
            
            [Association(Name="Supplier_Contract", Storage="_Supplier", ThisKey="SupplierId", OtherKey="SupplierId", IsForeignKey=true)]
            public Supplier Supplier
            {
                get
                {
                    return this._Supplier.Entity;
                }
                set
                {
                    Supplier previousValue = this._Supplier.Entity;
                    if (((previousValue != value)
                                || (this._Supplier.HasLoadedOrAssignedValue == false)))
                    {
                        this.SendPropertyChanging();
                        if ((previousValue != null))
                        {
                            this._Supplier.Entity = null;
                            previousValue.Contracts.Remove(this);
                        }
                        this._Supplier.Entity = value;
                        if ((value != null))
                        {
                            value.Contracts.Add(this);
                            this._SupplierId = value.SupplierId;
                        }
                        else
                        {
                            this._SupplierId = default(int);
                        }
                        this.SendPropertyChanged("Supplier");
                    }
                }
            }
            
            public event PropertyChangingEventHandler PropertyChanging;
            
            public event PropertyChangedEventHandler PropertyChanged;
            
            protected virtual void SendPropertyChanging()
            {
                if ((this.PropertyChanging != null))
                {
                    this.PropertyChanging(this, emptyChangingEventArgs);
                }
            }
            
            protected virtual void SendPropertyChanged(String propertyName)
            {
                if ((this.PropertyChanged != null))
                {
                    this.PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
                }
            }
            
            private void attach_ContractAssets(ContractAsset entity)
            {
                this.SendPropertyChanging();
                entity.Contract = this;
            }
            
            private void detach_ContractAssets(ContractAsset entity)
            {
                this.SendPropertyChanging();
                entity.Contract = null;
            }
            
            private void Initialize()
            {
                this._ContractAssets = new EntitySet<ContractAsset>(new Action<ContractAsset>(this.attach_ContractAssets), new Action<ContractAsset>(this.detach_ContractAssets));
                this._Supplier = default(EntityRef<Supplier>);
                OnCreated();
            }
            
            [OnDeserializing()]
            [System.ComponentModel.EditorBrowsableAttribute(EditorBrowsableState.Never)]
            public void OnDeserializing(StreamingContext context)
            {
                this.Initialize();
            }
            
            [OnSerializing()]
            [System.ComponentModel.EditorBrowsableAttribute(EditorBrowsableState.Never)]
            public void OnSerializing(StreamingContext context)
            {
                this.serializing = true;
            }
            
            [OnSerialized()]
            [System.ComponentModel.EditorBrowsableAttribute(EditorBrowsableState.Never)]
            public void OnSerialized(StreamingContext context)
            {
                this.serializing = false;
            }
        }
    }
    #pragma warning restore 1591

     

     

    Wednesday, September 10, 2008 2:44 PM