Category Archives: DynamicValidator

DynamicValidator

[RESOLVED]can you use the RequiredFieldValidator with a GridView data control in Visual Web Developer?

I'm new to Visual Web Developer.  I've created a web form with a GridView
displaying information from a SQL table, and enabled editing. Now I'd like
to add validation to several fields. I've tried using the
RequiredFieldValidator but am not having much luck. Could the reason be
that the GridView doesn't use TextBoxes per se? Rather I see it uses
asp:BoundFields with DataField attributes, not TextBoxes with id attributes.

My goal is to be able to build web forms that interact with SQL tables. If you know of an easier/better way to do it than I'm attempting,
please let me know

Thanks for any help/direction

Christian

to your reqfieldvalidators you need to use TemplateFields instead of boundfields .. 

<asp:TemplateField HeaderText="FirstName" SortExpression="FirstName">
    <EditItemTemplate>
        <asp:TextBox ID="TextBox1" runat="server"
            Text='<%# Bind("FirstName") %>'></asp:TextBox>
//Here you can use your validator ..
<asp:RequiredFieldValidator runat="server" id="reqName" controltovalidate="TextBox1" errormessage="Please enter your name!" />
    </EditItemTemplate>
    <ItemTemplate>
        <asp:Label ID="Label1" runat="server"
            Text='<%# Bind("FirstName") %>'></asp:Label>
    </ItemTemplate>
</asp:TemplateField>
Thanks to everyone for their replies.

FYI: The http://msdn.microsoft.com/en-us/library/bb332381.aspx link looked very promising but the article was from back in 2006-2007. I contacted the author, Scott Mitchell, to ask if the series of articles was still relevant. I'm sharing his reply here:

"Hi Christian. I wouldn’t recommend using Typed DataSets, which is the technology my tutorials detailed. It’s a defunct technology at this point.

Instead, I’d recommend using either Linq-to-SQL or Entity Framework. Scott Guthrie has a multi-part tutorial on using Linq-to-SQL:

http://scottonwriting.net/sowblog/archive/2010/07/27/links-to-scott-guthrie-s-using-linq-to-sql-tutorials.aspx

"

Thought I’d share this.  BTW, when I tried to convert from BoundFields to TemplateFields, as Akii suggested and Mr. Mitchell’s tutorial demonstrated, I wound up with DynamicData tags instead, so the RequiredFieldValidator still didn’t work.

Back to the drawing board …

Chris

Hi Christian,

According to your description, you are have using the DynamicData tags, and you want to validate it.

If so, please refer to the following code:

<%@ Page Language="C#" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<script runat="server">
  protected void Page_Init(object sender, EventArgs e)
  {
    DynamicDataManager1.RegisterControl(CustomersGridView);
  }
</script>

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
  <title>DynamicField Sample</title>
  <link href="~/Site.css" rel="stylesheet" type="text/css" />
</head>
<body>
  <form id="form1" runat="server">
    <div>

      <h2><%= CustomersDataSource.TableName%> Table</h2>

      <asp:DynamicDataManager ID="DynamicDataManager1" runat="server"
        AutoLoadForeignKeys="true" />

      <asp:ValidationSummary ID="ValidationSummary1" runat="server" EnableClientScript="true"
        HeaderText="List of validation errors"  />
      <asp:DynamicValidator runat="server" ID="DynamicValidator1"
        ControlToValidate="CustomersGridView" Display="None" />

      <asp:GridView ID="CustomersGridView" runat="server"
        AutoGenerateColumns="false"
        AutoGenerateEditButton="true"
        AutoGenerateDeleteButton="true"
        DataSourceID="CustomersDataSource"
        AllowPaging="true"
        AllowSorting="true"
        CssClass="gridview">
        <Columns>
          <asp:DynamicField DataField="CustomerID" />
          <asp:DynamicField DataField="FirstName" />
          <asp:DynamicField DataField="LastName" />
        </Columns>
      </asp:GridView>

      <!-- This example uses Microsoft SQL Server and connects   -->
      <!-- to the AdventureWorksLT sample database.              -->
      <asp:LinqDataSource ID="CustomersDataSource" runat="server"
        TableName="Customers"
        ContextTypeName="AdventureWorksLTDataContext"
        EnableUpdate="true"
        EnableDelete="true" >
      </asp:LinqDataSource>

    </div>
  </form>
</body>
</html>

There have a tutorial about validation control in gridview, please try to refer to it:
http://msdn.microsoft.com/en-us/library/bb426882.aspx

Hope it helps.

If it can’t help you, please post your sample code to here, maybe somebody can help you.

Best Regards,
Terry Guo

[RESOLVED]FormView & Model Binding

Hi,

I am using a FormView with ModelBinding in my WebForms application, using VS2012 Pro. I am binding a form to my Db Table with CRUD operations enabled like so:

My FormView:

<asp:ValidationSummary ID="ValidationSummary1" runat="server" ShowModelStateErrors="true" />
<asp:FormView runat="server" ID="addDogForm"
    ItemType="PoochiesPrix.Models.DogInfo"
    InsertMethod="addDogForm_InsertItem" DefaultMode="Insert"
    RenderOuterTable="false" OnItemInserted="addDogForm_ItemInserted">
    <InsertItemTemplate>
        <fieldset>
            <ol>
                <asp:DynamicEntity ID="DynamicEntity1" runat="server" Mode="Insert" />
            </ol>
            <asp:Button ID="btnSave" runat="server" Text="Save" CommandName="Insert" />
            <asp:Button ID="btnCancel" runat="server" Text="Cancel" CausesValidation="false" OnClick="cancelButton_Click" />
        </fieldset>
    </InsertItemTemplate>
</asp:FormView>

Then in my code behind I am I am binding my data using ModelBinding:

public void addDogForm_InsertItem()
        {
            var item = new DogInfo();

            TryUpdateModel(item);
            if (ModelState.IsValid)
            {
                using (PoochiesContext db = new PoochiesContext())
                {
                    db.DogInfoes.Add(item);
                    db.SaveChanges();
                }
            }
        }

Everything is working well, except that on my Model I have two properties that are composite keys in another table that i need to reference

        public int OwnerID { get; set; }
        public int dogTypeID { get; set; }

These two properties are showing up on my From, and I dont want them too. I am using DynamicData so my forms are built from my model dynamically. These properties are showing up on my form as:

OwnerID  //with a textbox to enter text

DogTypeId  //with a textbox to enter text

I dont want to show these on my form. Here is the raw HTML from the page. How can Not return them, or can I use jQuery to hide them? What is the best way to handle this? I do not want any perfomance concerns.

Raw HTML

 <li class="DDLightHeader" style="list-style-type: none;">
            <label for="FeaturedContent_addDogForm_ctl01_ctl13___OwnerID_TextBox1" id="FeaturedContent_addDogForm_ctl01_ctl13_Label1">OwnerID</label>
        </li>
        <li style="list-style-type: none;">
            <input name="ctl00$FeaturedContent$addDogForm$ctl01$ctl13$__OwnerID$TextBox1" type="number" size="10" id="FeaturedContent_addDogForm_ctl01_ctl13___OwnerID_TextBox1" />

<span data-val-controltovalidate="FeaturedContent_addDogForm_ctl01_ctl13___OwnerID_TextBox1" data-val-errormessage="The OwnerID field is required." id="FeaturedContent_addDogForm_ctl01_ctl13___OwnerID_RequiredFieldValidator1" title="The OwnerID field is required." class="DDControl DDValidator" data-val="true" data-val-evaluationfunction="RequiredFieldValidatorEvaluateIsValid" data-val-initialvalue="" style="visibility:hidden;">*</span>
<span data-val-controltovalidate="FeaturedContent_addDogForm_ctl01_ctl13___OwnerID_TextBox1" data-val-errormessage="The field OwnerID must be a valid integer." id="FeaturedContent_addDogForm_ctl01_ctl13___OwnerID_CompareValidator1" title="The field OwnerID must be a valid integer." class="DDControl DDValidator" data-val="true" data-val-type="Integer" data-val-evaluationfunction="CompareValidatorEvaluateIsValid" data-val-operator="DataTypeCheck" style="visibility:hidden;">*</span>
<span data-val-controltovalidate="FeaturedContent_addDogForm_ctl01_ctl13___OwnerID_TextBox1" data-val-enabled="False" id="FeaturedContent_addDogForm_ctl01_ctl13___OwnerID_RegularExpressionValidator1" class="DDControl DDValidator" data-val="true" data-val-evaluationfunction="RegularExpressionValidatorEvaluateIsValid" style="visibility:hidden;">*</span>
<span data-val-controltovalidate="FeaturedContent_addDogForm_ctl01_ctl13___OwnerID_TextBox1" data-val-enabled="False" id="FeaturedContent_addDogForm_ctl01_ctl13___OwnerID_RangeValidator1" class="DDControl DDValidator" data-val="true" data-val-type="Integer" data-val-evaluationfunction="RangeValidatorEvaluateIsValid" data-val-maximumvalue="100" data-val-minimumvalue="0" style="visibility:hidden;">*</span>
<span data-val-controltovalidate="FeaturedContent_addDogForm_ctl01_ctl13___OwnerID_TextBox1" id="FeaturedContent_addDogForm_ctl01_ctl13___OwnerID_DynamicValidator1" class="DDControl DDValidator" data-val="true" style="visibility:hidden;">*</span>


        </li>
    
           <li class="DDLightHeader" style="list-style-type: none;">
            <label for="FeaturedContent_addDogForm_ctl01_ctl14___dogTypeID_TextBox1" id="FeaturedContent_addDogForm_ctl01_ctl14_Label1">dogTypeID</label>
        </li>
        <li style="list-style-type: none;">
            <input name="ctl00$FeaturedContent$addDogForm$ctl01$ctl14$__dogTypeID$TextBox1" type="number" size="10" id="FeaturedContent_addDogForm_ctl01_ctl14___dogTypeID_TextBox1" />

<span data-val-controltovalidate="FeaturedContent_addDogForm_ctl01_ctl14___dogTypeID_TextBox1" data-val-errormessage="The dogTypeID field is required." id="FeaturedContent_addDogForm_ctl01_ctl14___dogTypeID_RequiredFieldValidator1" title="The dogTypeID field is required." class="DDControl DDValidator" data-val="true" data-val-evaluationfunction="RequiredFieldValidatorEvaluateIsValid" data-val-initialvalue="" style="visibility:hidden;">*</span>
<span data-val-controltovalidate="FeaturedContent_addDogForm_ctl01_ctl14___dogTypeID_TextBox1" data-val-errormessage="The field dogTypeID must be a valid integer." id="FeaturedContent_addDogForm_ctl01_ctl14___dogTypeID_CompareValidator1" title="The field dogTypeID must be a valid integer." class="DDControl DDValidator" data-val="true" data-val-type="Integer" data-val-evaluationfunction="CompareValidatorEvaluateIsValid" data-val-operator="DataTypeCheck" style="visibility:hidden;">*</span>
<span data-val-controltovalidate="FeaturedContent_addDogForm_ctl01_ctl14___dogTypeID_TextBox1" data-val-enabled="False" id="FeaturedContent_addDogForm_ctl01_ctl14___dogTypeID_RegularExpressionValidator1" class="DDControl DDValidator" data-val="true" data-val-evaluationfunction="RegularExpressionValidatorEvaluateIsValid" style="visibility:hidden;">*</span>
<span data-val-controltovalidate="FeaturedContent_addDogForm_ctl01_ctl14___dogTypeID_TextBox1" data-val-enabled="False" id="FeaturedContent_addDogForm_ctl01_ctl14___dogTypeID_RangeValidator1" class="DDControl DDValidator" data-val="true" data-val-type="Integer" data-val-evaluationfunction="RangeValidatorEvaluateIsValid" data-val-maximumvalue="100" data-val-minimumvalue="0" style="visibility:hidden;">*</span>
<span data-val-controltovalidate="FeaturedContent_addDogForm_ctl01_ctl14___dogTypeID_TextBox1" id="FeaturedContent_addDogForm_ctl01_ctl14___dogTypeID_DynamicValidator1" class="DDControl DDValidator" data-val="true" style="visibility:hidden;">*</span>


        </li>
    

Model Binding is a new animal to me, but I would like to get advice on the best way to keep the ID properties from rendering. I though about trying to do it in my code behind, but LINQ is new to me too. Any advice would be great. Thanks.

P.S. Here is my model

 public class DogInfo
    {
        
        [Key, Display(Name= "DogInfoID")]
        [ScaffoldColumn(false)]
        public int DogInfoID { get; set; }
        
        [Required(ErrorMessage="License number is required"),StringLength(15), Display(Name= "License Number")]
        public string licenseNumber { get; set; }

        [Required(ErrorMessage = "A date is required"), Display(Name = "Date License was Renewed")]
        public DateTime dateLicenseRenewed { get; set; }

        [Required(ErrorMessage = "A date is required"), Display(Name = "Date License Expires")]
        public DateTime dateLicenseExpires { get; set; }

        [Required(ErrorMessage="Name is required"), StringLength(35), Display(Name="Dogs Name")]
        public string name { get; set; }

        [Required(ErrorMessage = "Enter Male or Female"), StringLength(6, MinimumLength = 4), Display(Name = "Sex")]
        public string sex { get; set; }

        [Display(Name= "Breed")]
        public string breed { get; set; }

        [Required(ErrorMessage="Required. If you do not know your dogs DOB, enter an approximate date."), Display(Name = "Birth Date") ]
        public DateTime birthDate { get; set; }

        [Display(Name= "Microchip Number")]
        public string microchipNumber { get; set; }

        [Display(Name= "Breed Registration")]
        public string breedRegistration { get; set; }

        [Display(Name= "Coat Color")]
        public string coatColor { get; set; }

        [Display(Name= "Eye Color")]
        public string eyeColor { get; set; }

        [Display(Name = "Breed Shelter Name")]
        public string breedShelterName { get; set; }

        [Display(Name= "Date Acquired")]
        public Nullable<DateTime> dateAcquired { get; set; }

        public int OwnerID { get; set; }
        public int dogTypeID { get; set; }
       
        public virtual Owner Owner { get; set; }
        public virtual Record Record { get; set; }
        public virtual ICollection<DogPic> DogPics { get; set; }
        public virtual ICollection<Record> Records { get; set; }
    }

Hi Mark_F,

Based on your description, my understanding is that you would like to display specify column.

If so, I suggest you using DynamicControl to specify columns, like this:

<InsertItemTemplate>
        <fieldset>
            <ol>
				<asp:DynamicControl runat="server" DataField="YourColumnName" Mode="Insert" />
                <%--<asp:DynamicEntity runat="server" Mode="Insert" />--%>
            </ol>
            <asp:Button runat="server" Text="Insert" CommandName="Insert" />
            <asp:Button runat="server" Text="Cancel" CausesValidation="false" OnClick="cancelButton_Click" />
        </fieldset>
    </InsertItemTemplate>

More information about DynamicControl please refer to:
http://msdn.microsoft.com/en-us/library/system.web.dynamicdata.dynamiccontrol(v=vs.110).aspx

Hope it helps.

Best Regards,
Terry Guo

Hi  Terry,

So, you are saying I can specify which columns I want to display byspecifying them in here:

<fieldset>
            <ol>
                <asp:DynamicEntity ID="DynamicEntity1" runat="server" Mode="Insert" /> //place them here
            </ol>
            <asp:Button ID="btnSave" runat="server" Text="Save" CommandName="Insert" />
            <asp:Button ID="btnCancel" runat="server" Text="Cancel" CausesValidation="false" OnClick="cancelButton_Click" />
        </fieldset>

Do I need to specify each Like this:

<asp:DynamicControl runat="server" DataField="name" Mode="Insert" />
<asp:DynamicControl runat="server" DataField="address" Mode="Insert" />
<asp:DynamicControl runat="server" DataField="date" Mode="Insert" />
<asp:DynamicControl runat="server" DataField="town" Mode="Insert" />
<asp:DynamicControl runat="server" DataField="country" Mode="Insert" />
<asp:DynamicControl runat="server" DataField="email" Mode="Insert" />

//these are just examples, I realize I will have to put the exact name of my Db fields here

Hi Mark_F,

Yes, the DynamicEntity will generate the all column automatically, but when you want to display specify column, you can using the DynamicControl.

Best Regards,
Terry Guo

Great, thanks allot for the information, I just added the fields that I wanted to display like this:

<asp:DynamicControl runat="server" DataField="firstName" Mode="Insert" />
<asp:DynamicControl runat="server" DataField="lastName" Mode="Insert" />
<asp:DynamicControl runat="server" DataField="address" Mode="Insert" />
<asp:DynamicControl runat="server" DataField="city" Mode="Insert" />
<asp:DynamicControl runat="server" DataField="state" Mode="Insert" />
<asp:DynamicControl runat="server" DataField="email" Mode="Insert" />

Thank you, worked perfectly! Cheers!

[RESOLVED]Using Datepicker with FormView

Hi All,

I have a Web forms application using EF Code First. I am using ModelBinding, and all is going well. I decided to try my hand at DynamicDataEntities which I installed from NuGet packageManager. I have a FormView that is bound to my entity data model, and
Im using the DynamicDataTemplates. I was just letting ASP build my form for me with the input fields, which worked fine, but, I need more control over the date fields. I want to add a jQuery Datepicker on the Date fields but I am having trouble.  I was using
this:

 <%--I was using a DynamicDataEntiy to render my form from my Model--%>

<asp:FormView ID="addDogForm" runat="server" ItemType="PoochiesPrix_4.Models.DogInfo"
        InsertMethod="addDogForm_InsertItem" DefaultMode="Insert"
        RenderOuterTable="false" OnItemInserted="addDogForm_ItemInserted">
        <InsertItemTemplate>
        <fieldset>
            <ol>
                <%--<asp:DynamicEntity ID="DynamicEntity1" runat="server" Mode="Insert" />--%>
           </ol>
            <asp:Button ID="btnSave" runat="server" Text="Save" CommandName="Insert" />
            <asp:Button ID="btnCancel" runat="server" Text="Cancel" CausesValidation="false" OnClick="cancelButton_Click" />
        </fieldset>
    </InsertItemTemplate>
    </asp:FormView>

This worked fine, but, In my Model:

//I have date fields that I want to show a Datepicker for

public class DogInfo
    {
        [Key, Display(Name = "DogInfoID")]
        [ScaffoldColumn(false)]
        public int DogInfoID { get; set; }

        [Required(ErrorMessage = "Name is required"), StringLength(35), Display(Name = "Dogs Name")]
        public string name { get; set; }

        [Required(ErrorMessage = "License number is required"), StringLength(15), Display(Name = "License Number")]
        public string licenseNumber { get; set; }

        [Required(ErrorMessage = "A date is required"), Display(Name = "Date License was Renewed")]
        [Range(typeof(DateTime), "1/1/2014", "1/1/3000", ErrorMessage = "Please provide a renewal date after 1/1/2014")]
        [DisplayFormat(ApplyFormatInEditMode = true, DataFormatString = "{0:d}")]
        public DateTime dateLicenseRenewed { get; set; }

        [Required(ErrorMessage = "A date is required"), Display(Name = "Date License Expires")]
        [Range(typeof(DateTime), "1/1/2014", "1/1/3000", ErrorMessage = "Please provide a date after 1/1/2014")]
        [DisplayFormat(ApplyFormatInEditMode = true, DataFormatString = "{0:d}")]
        public DateTime dateLicenseExpires { get; set; }

        [Display(Name = "Coat Color")]
        public string coatColor { get; set; }

        [Display(Name = "Eye Color")]
        public string eyeColor { get; set; }

        [Required(ErrorMessage = "Enter Male or Female"), StringLength(6, MinimumLength = 4), Display(Name = "Sex")]
        public string sex { get; set; }

        [Display(Name = "Breed")]
        public string breed { get; set; }

        [Required(ErrorMessage = "Required. If you do not know your dogs DOB, enter an approximate date."), Display(Name = "Birth Date")]
        public DateTime birthDate { get; set; }

        [Display(Name = "Microchip Number")]
        public string microchipNumber { get; set; }

        [Display(Name = "Breed Registration")]
        public string breedRegistration { get; set; }

        [Display(Name = "Breed Shelter Name")]
        public string breedShelterName { get; set; }

        [Display(Name = "Date Acquired")]
        [Range(typeof(DateTime), "1/1/1900", "1/1/3000", ErrorMessage = "Please an approximate date after 1/1/1900")]
        [DisplayFormat(ApplyFormatInEditMode = true, DataFormatString = "{0:d}")]
        public Nullable<DateTime> dateAcquired { get; set; }

        [ScaffoldColumn(false)]
        public Guid OwnerID { get; set; }

        [EnumDataType(typeof(DogType)), Display(Name = "Dog Type")]
        public DogType dogType{ get; set; }


        [ScaffoldColumn(false)]
        public ICollection<DogPic> DogPics { get; set; }

        [ScaffoldColumn(false)]
        public List<Veternarian> Veternarians { get; set; }
    }
    public enum DogType
    {
        Adult,
        Puppy
    }

I have tried explicitedly adding the entities to the page in its each DynamicControl like this:

HTML:

<asp:FormView ID="addDogForm" runat="server" ItemType="PoochiesPrix_4.Models.DogInfo"
        InsertMethod="addDogForm_InsertItem" DefaultMode="Insert"
        RenderOuterTable="false" OnItemInserted="addDogForm_ItemInserted">
        <InsertItemTemplate>
        <fieldset>
            <ol>
                <%--<asp:DynamicEntity ID="DynamicEntity1" runat="server" Mode="Insert" />--%>
                <asp:DynamicControl ID="DynamicControl1" runat="server" DataField="name" Mode="Insert" />
                <asp:DynamicControl ID="DynamicControl2" runat="server" DataField="licenseNumber" Mode="Insert" />
                <asp:DynamicControl ID="DynamicControl3" runat="server" DataField="dateLicenseRenewed" Mode="Insert" />
                <asp:DynamicControl ID="DynamicControl4" runat="server" DataField="dateLicenseExpires" Mode="Insert" />
                <asp:DynamicControl ID="DynamicControl5" runat="server" DataField="coatColor" Mode="Insert" />
                <asp:DynamicControl ID="DynamicControl6" runat="server" DataField="eyeColor" Mode="Insert" />
                <asp:DynamicControl ID="DynamicControl7" runat="server" DataField="sex" Mode="Insert" />
                <asp:DynamicControl ID="DynamicControl8" runat="server" DataField="breed" Mode="Insert" />
                <asp:DynamicControl ID="DynamicControl9" runat="server" DataField="birthDate" Mode="Insert" />
                <asp:DynamicControl ID="DynamicControl10" runat="server" DataField="microchipNumber" Mode="Insert" />
                <asp:DynamicControl ID="DynamicControl11" runat="server" DataField="breedRegistration" Mode="Insert" />
                <asp:DynamicControl ID="DynamicControl12" runat="server" DataField="breedShelterName" Mode="Insert" />
                <asp:DynamicControl ID="DynamicControl13" runat="server" DataField="dateAcquired" Mode="Insert" />
                 <asp:DynamicControl ID="DynamicControl14" runat="server" DataField="dogType" Mode="Insert" />

            </ol>
            <asp:Button ID="btnSave" runat="server" Text="Save" CommandName="Insert" />
            <asp:Button ID="btnCancel" runat="server" Text="Cancel" CausesValidation="false" OnClick="cancelButton_Click" />
        </fieldset>
    </InsertItemTemplate>
    </asp:FormView>

Then editing the DateTime_Edit.ascx, Dynamic Template mark up:

<%-- Use the Juice Datepicker--%>

<juice:Datepicker runat="server" id="t1" targetcontrolid="DynamicControl3" />
<asp:TextBox ID="TextBox1" runat="server" CssClass="DDTextBox" Text='<%# FieldValueEditString %>' Columns="20"></asp:TextBox

Then in my DateTime_Edit.ascx.cs, I set a date range for my Calender:

protected void Page_Load(object sender, EventArgs e)
        {
            TextBox1.ToolTip = Column.Description;

            SetUpValidator(RequiredFieldValidator1);
            SetUpValidator(RegularExpressionValidator1);
            SetUpValidator(DynamicValidator1);
            SetUpCustomValidator(DateValidator);

        //when my calendar displays, restrict the date range the user can pick.

            RangeAttribute ra = (RangeAttribute)Column.Attributes[typeof(RangeAttribute)];
            if (ra != null)
            {
                t1.MinDate = ra.Minimum.ToString();
                t1.MaxDate = ra.Maximum.ToString();

            }
                
        }

I am getting an error that the value is null in my calendar. I know why this is happening, because I am using EF Code first, and I am dropping and recreating my Database evertime I run my application if my Model changes. I am not sure how to set a default
value in my code behind for this Calendar so that i do not get an error. I would like to set the current date as the date that displays. I believe that this will eliminate the null error too. I’m not sure though, since EF is using my database to build the
form. i hope that I explained this clear enough. Iwould like some direction on how to go about setting default values on my DynamidDataTemplate fileds.

Hi,

If you want to set default date for the jQuery Datepicker, you could try:

$( ".selector" ).datepicker( "setDate", new Date());
// Or on the init
$( ".selector" ).datepicker({ defaultDate: new Date() });

For more information, you could refer to:

http://stackoverflow.com/questions/14580749/jquery-datepicker-set-default-date

http://stackoverflow.com/questions/4915990/set-todays-date-as-default-date-in-jquery-ui-datepicker

Regards

Shawn,

Thanks allot for the info.It helped allot. I have all of my DatePickers working now.I found that I just needed to set each Datepicker for TexBox1 in the DynamicDataEntity Template, DateTime_Edit.ascx:

<juice:Datepicker runat="server" id="t1" targetcontrolid="TextBox1" />
<juice:Datepicker runat="server" id="t2" targetcontrolid="TextBox1" />
<juice:Datepicker runat="server" id="t3" targetcontrolid="TextBox1" />
<juice:Datepicker runat="server" id="t4" targetcontrolid="TextBox1" />
<asp:TextBox ID="TextBox1" runat="server" CssClass="DDTextBox" Text='<%# FieldValueEditString %>' Columns="20"></asp:TextBox>

Then in the DateTime_Edit.cs file, i did this:

RangeAttribute ra = (RangeAttribute)Column.Attributes[typeof(RangeAttribute)];
            if (ra != null)
            {
                t1.MinDate = ra.Minimum.ToString();
                t1.MaxDate = ra.Maximum.ToString();
                t2.MinDate = ra.Minimum.ToString();
                t2.MaxDate = ra.Maximum.ToString();
                t4.MinDate = ra.Minimum.ToString();
                t4.MaxDate = ra.Maximum.ToString();

            }

In my Page, I put a script:

<script type="text/javascript">
        $(function () {
            $('#t1').datepicker();
            $('#t1').datepicker('setDate', new Date());
        });
    </script>

For each one that I wanted a default date set in. Actually, when I set the targetcontrolid to "TextBox1, the page ran fine." Thanks for the links though. They are good. Cheers!