This is a migrated thread and some comments may be shown as answers.

[Solved] Default Value in textbox for Popup

7 Answers 215 Views
Date/Time Pickers
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Neil
Top achievements
Rank 1
Neil asked on 15 Jul 2011, 12:08 AM

I have a popup with multiple date fields.

I'd like to be able to display the value from the database if one exists but if not, instead of the current date, default to null or space but not the current date.

 

Can you tell me how to do this?

 

I'd prefer not to modify the Telerik control itself and would rather do it according to the requirements on the page.

Thanks

7 Answers, 1 is accepted

Sort by
0
Georgi Krustev
Telerik team
answered on 15 Jul 2011, 07:33 AM
Hello Neil,

 
Unfortunately, I am not sure what your scenario exactly is. Could you please elaborate more on this? Code snippet or running test project would be really helpful.

Best wishes,
Georgi Krustev
the Telerik team

Register for the Q2 2011 What's New Webinar Week. Mark your calendar for the week starting July 18th and book your seat for a walk through of all the exciting stuff we will ship with the new release!

0
Neil
Top achievements
Rank 1
answered on 15 Jul 2011, 05:23 PM
Thanks for replying Georgi,

I'm including some code examples, shortened for brevity.

In the Model folder, I have a dbml whose designer contains the following:
  

[global::System.Data.Linq.Mapping.ColumnAttribute(Storage="_Some_Dt", DbType="DateTime")]
public System.Nullable<System.DateTime> Some_Dt
{
    get
    {
        return this._Some_Dt;
    }
    set
    {
        if ((this._Some_Dt != value))
        {
            this.OnSome_DtChanging(value);
            this.SendPropertyChanging();
            this._Some_Dt = value;
            this.SendPropertyChanged("Some_Dt");
            this.OnSome_DtChanged();
        }
    }
}

Also in the Model folder, i have a DataContext.cs file that contains the following:

[MetadataType(typeof(DBTable_Metadata))]
public partial class DBTable
{
    public class DBTable_Metadata
    {
          
        [UIHint("DateTime")]
        public System.Nullable<System.DateTime> Some_Dt { get; set; }
    }
}

In my myPopup.ascx file, I have defined the following:

<div class="editor-label">
    <label>Some Date</label>
</div> 
<div class="editor-Field">
    <%= Html.EditorFor(c => c.Some_Dt)%>
    <%= Html.ValidationMessageFor(c => c.Some_Dt)%>
</div>

In my view, I have a grid defined as follows:

<%= Html.Telerik().Grid<Bpa.Transmission.Administration.Models.Asset_IN>()
  .Name("Grid")
  .DataKeys(keys =>
      {
          keys.Add(p => p.My_Key);
      })
  .Columns(columns =>
  {
      columns.Command(commands =>
      {
          commands.Edit().ButtonType(GridButtonType.Image);
      }).Title("Commands");
      columns.Bound(o => o.Some_Dt).Title("Some Date").Width(30).Format("{0:MM/dd/yyyy}");
      }
  })
  .DataBinding(dataBinding => dataBinding.Ajax()
      .Select("_SelectClientSide", "DBTable")
      .Update("_SaveAjaxEditing", "DBTable"))
  .Pageable()
  .Filterable()
  .Sortable()
  .Editable(editing => editing.Mode(GridEditMode.PopUp).TemplateName("MyPopup").Window(w => w.Resizable(r => r.Enabled(true))))
%>

The DateTime.ascx file under Shared/EditorTemplates looks like this:

<%@ Control Language="C#" Inherits="System.Web.Mvc.ViewUserControl<DateTime?>" %>
  
<%= Html.Telerik().DateTimePicker()
        .Name(ViewData.TemplateInfo.GetFullHtmlFieldName(string.Empty))
        .HtmlAttributes(new { id = ViewData.TemplateInfo.GetFullHtmlFieldName(string.Empty) + "_wrapper" })
        .Value(Model > DateTime.MinValue? Model : DateTime.Today)
%>

I don't want to change the the .Value(Model...) statement above for all Views, just the MyPopup.ascx view, so that the default value (DateTime.Today) DOES NOT APPEAR.

I didn't include the controller logic - i don't see where it's necessary at this point but if you insist, I can.

Does this help?

0
Georgi Krustev
Telerik team
answered on 18 Jul 2011, 10:38 AM
Hello Neil,

 
Thank you for the code snippets.

I have used them in my attempt to replicate the issue, but to no avail. Could you please check it and modify it in order to reproduce it?

Regards,
Georgi Krustev
the Telerik team

Register for the Q2 2011 What's New Webinar Week. Mark your calendar for the week starting July 18th and book your seat for a walk through of all the exciting stuff we will ship with the new release!

0
Neil
Top achievements
Rank 1
answered on 19 Jul 2011, 12:32 AM
Ok, let's start over.

The Date.ascx and DateTime.ascx files supplied by Telerik, and found in Views/Shared/EditorTemplates/,  contain the following line of code:
.Value(Model > DateTime.MinValue? Model : DateTime.Today)

 

This is obviously putting the current date and time in the TextBox that this control creates.  I have proven this by altering the files.

I have an editor template that is used for a popup.  The related partial class in the model contains this:

 

[UIHint("DateTime")] 
public DateTime? Begin_Dt { get; set; }

 
What happens in my world is, if the value in the database is null, the textbox contains the current date when the popup displays.

This is expected behavior considering the code in the Telerik .ascx files.

I don't want that.

I want the default value to display nothing, zip, zilch, nada, bupkis, zed.  In other words, I want a null value in the textbox.

I want this to happen WITHOUT having to modify the telerik control to look like this:

.Value(Model > DateTime.MinValue? Model : null

Can this be done?

Thanks,

neil

0
Georgi Krustev
Telerik team
answered on 21 Jul 2011, 09:10 AM
Hello Neil,

 
In order to achieve your goal you will need to define custom editor template and modify UIHint to take the name of the custom editor template.

For instance, create in the Shared/EditorTemplates or in specific View folder "DateTimeWithoutDefaults.ascx" and set [UIHint("DateTimeWithoutDefaults")].

Kind regards,
Georgi Krustev
the Telerik team

Register for the Q2 2011 What's New Webinar Week. Mark your calendar for the week starting July 18th and book your seat for a walk through of all the exciting stuff we will ship with the new release!

0
Deanna Terry
Top achievements
Rank 1
answered on 06 Jan 2012, 11:10 PM
I'm having the exact same problem... did you ever figure out a solution?  If defining the custom editor template was the key, would you mind sharing your template code with me?  I'm pretty new to MVC and the Telerik extensions...

Thanks,
-Deanna
0
Neil
Top achievements
Rank 1
answered on 06 Jan 2012, 11:35 PM

Hi Deanna,

 

Here's what i recall doing...

 

In the Views/Shared/EditorTemplates folder, you'll find the standard DateTimePicker.  I created a new DateTimePicker called 'DateTimeNoDefault.ascx' and placed it in that folder.  It looks almost identical to the one out of the box:

<%@ Control Language="C#" 
Inherits="System.Web.Mvc.ViewUserControl<DateTime?>"%>
<%= Html.Telerik().DateTimePicker()
          .Name(ViewData.TemplateInfo.GetFullHtmlFieldName(string.Empty))
          .HtmlAttributes(new { id = 
             ViewData.TemplateInfo.GetFullHtmlFieldName(string.Empty) + "_wrapper" })
          .Value(Model > DateTime.MinValue ? Model : null)
%>

To use it, in a popup for example, I have, in my Models folder, a partial class with a decorated field:

              
[UIHint("DateTimeNoDefault")]
public System.Nullable<System.DateTime> SomeDate { get; set; }

Hope this helps...

n

Tags
Date/Time Pickers
Asked by
Neil
Top achievements
Rank 1
Answers by
Georgi Krustev
Telerik team
Neil
Top achievements
Rank 1
Deanna Terry
Top achievements
Rank 1
Share this question
or