Having trouble With Minimal Data Attributes working

Last post 11-12-2009 5:08 AM by sjnaughton. 11 replies.

Sort Posts:

  • Having trouble With Minimal Data Attributes working

    11-08-2009, 1:47 AM
    • All-Star
      23,823 point All-Star
    • pkellner
    • Member since 11-12-2004, 10:42 AM
    • San Jose, California
    • Posts 3,579
    • ASPInsiders
      Moderator
      TrustedFriends-MVPs

    I've made my own page in the futures DD project release.

    To my ObjectDataSource Object I'm returning, I've added the MetadataType attribute and put some attributes on the properties as follows:

      [MetadataType(typeof(MembershipUserWrapper))]
        public class MembershipUserWrapper : MembershipUser
        {
    
            [DataType(DataType.PhoneNumber)]
            [Required]
            public override string Comment { get; set; }


     Then,  in my codebehind, I have:

       public partial class ObjectDataSourceSample : System.Web.UI.Page {
            protected void Page_Init() {
                // Extension method syntax
                ProductsList.EnableDynamicData(typeof(MembershipUserWrapper));
     
    I create a simple updateable gridview, press the edit button, and the validation does not happen.  What am I missing?
    Thanks,
    


     

    Peter Kellner
    http://peterkellner.net
    Microsoft MVP • ASPInsider
  • Re: Having trouble With Minimal Data Attributes working

    11-08-2009, 7:27 AM
    • Star
      12,374 point Star
    • sjnaughton
    • Member since 04-29-2008, 1:11 PM
    • Newton-le-Willows, Merseyside, UK
    • Posts 2,575
    • TrustedFriends-MVPs

    Hi Pkellner, is "ProductsList" your GridView, and have you tried this with the Preview or Beta 2?

    Steve Big Smile

    Always seeking an elegant solution.
    [Oh! If olny I colud tpye!]
    c# Bits blog
    Oh, and don't forget to mark as answer any posts that help you Big Smile
    Filed under:
  • Re: Having trouble With Minimal Data Attributes working

    11-08-2009, 10:01 AM
    • All-Star
      23,823 point All-Star
    • pkellner
    • Member since 11-12-2004, 10:42 AM
    • San Jose, California
    • Posts 3,579
    • ASPInsiders
      Moderator
      TrustedFriends-MVPs

    Yes, ProductList is my gridview.  I'm trying to morph the sampe into my problem. (and this is dd futures build)

     </div>
        <asp:GridView ID="ProductsList" runat="server" 
            DataSourceID="ObjectDataSource1" AllowPaging="True" BackColor="White" 
            BorderColor="#CCCCCC" BorderStyle="None" BorderWidth="1px" CellPadding="4" 
            ForeColor="Black" GridLines="Horizontal" AutoGenerateColumns="False" 
            DataKeyNames="UserName">
            <Columns>
                <asp:CommandField ShowDeleteButton="True" ShowEditButton="True" />
                <asp:BoundField DataField="UserName" HeaderText="UserName" ReadOnly="True" 
                    SortExpression="UserName" />
             
                <asp:BoundField DataField="Email" HeaderText="Email" SortExpression="Email" />
               
                <asp:BoundField DataField="Comment" HeaderText="Comment" 
                    SortExpression="Comment" />
                <asp:CheckBoxField DataField="IsApproved" HeaderText="IsApproved" 
                    SortExpression="IsApproved" />
               
            </Columns>
            <FooterStyle BackColor="#CCCC99" ForeColor="Black" />
            <PagerStyle BackColor="White" ForeColor="Black" HorizontalAlign="Right" />
            <SelectedRowStyle BackColor="#CC3333" Font-Bold="True" ForeColor="White" />
            <HeaderStyle BackColor="#333333" Font-Bold="True" ForeColor="White" />
        </asp:GridView>
        <asp:ObjectDataSource ID="ObjectDataSource1" runat="server" DeleteMethod="Delete" 
            InsertMethod="Insert" SelectMethod="GetMembers" 
            TypeName="MembershipUtilities.MembershipUserODS" UpdateMethod="Update" 
            OldValuesParameterFormatString="{0}">


     

    Peter Kellner
    http://peterkellner.net
    Microsoft MVP • ASPInsider
  • Re: Having trouble With Minimal Data Attributes working

    11-08-2009, 10:36 AM
    • Star
      12,374 point Star
    • sjnaughton
    • Member since 04-29-2008, 1:11 PM
    • Newton-le-Willows, Merseyside, UK
    • Posts 2,575
    • TrustedFriends-MVPs

    pkellner:
    (and this is dd futures build)
     

    Are we talking the old Futures project release in 2008? because I don't think there has been support for the ObjectDataSource for a while in that they had the DynamicObjectDataSource but I think in the laest Preview that has bee replaced by the DomainDataSource, I may be wrong on this but I have not seen ObjectDataSource in DD for a while... Embarrassed

    Steve Big Smile

    Always seeking an elegant solution.
    [Oh! If olny I colud tpye!]
    c# Bits blog
    Oh, and don't forget to mark as answer any posts that help you Big Smile
    Filed under:
  • Re: Having trouble With Minimal Data Attributes working

    11-08-2009, 10:51 AM
    • All-Star
      23,823 point All-Star
    • pkellner
    • Member since 11-12-2004, 10:42 AM
    • San Jose, California
    • Posts 3,579
    • ASPInsiders
      Moderator
      TrustedFriends-MVPs

    when I set autogeneratecolumns to true, the validation kind of works.  It respects my [Required] attribute but not the [DataType(DataType.PhoneNumber)] one.  So, also, how to I get my own fields to work?  I tried DynamicField as below and it seems to ignore the attributes

     

    <asp:DynamicField DataField="Email" HeaderText="Email" SortExpression="Email" />

    Peter Kellner
    http://peterkellner.net
    Microsoft MVP • ASPInsider
  • Re: Having trouble With Minimal Data Attributes working

    11-08-2009, 12:22 PM
    • Star
      12,374 point Star
    • sjnaughton
    • Member since 04-29-2008, 1:11 PM
    • Newton-le-Willows, Merseyside, UK
    • Posts 2,575
    • TrustedFriends-MVPs

    Hi Peter, I don't believe that the DataType will add any extra validation to the model, all you are doing is saying this dataType is a PhoneNumber, now if there is a fieldTemplate Called PhoneNumber_Edit.ascx and PhoneNumber.ascx then you will get any extra validation that is defined in the custom FiledTemplate. Think of DataType as a looser form of UIHint.

    Steve Big Smile

    Always seeking an elegant solution.
    [Oh! If olny I colud tpye!]
    c# Bits blog
    Oh, and don't forget to mark as answer any posts that help you Big Smile
    Filed under:
  • Re: Having trouble With Minimal Data Attributes working

    11-08-2009, 3:53 PM
    • All-Star
      23,823 point All-Star
    • pkellner
    • Member since 11-12-2004, 10:42 AM
    • San Jose, California
    • Posts 3,579
    • ASPInsiders
      Moderator
      TrustedFriends-MVPs

    Thanks sjnaughton,

    how about my issue around only working if I say "AutoGenerateFields"?  What am I missing there? 

    Peter Kellner
    http://peterkellner.net
    Microsoft MVP • ASPInsider
  • Re: Having trouble With Minimal Data Attributes working

    11-08-2009, 7:28 PM
    • Star
      12,374 point Star
    • sjnaughton
    • Member since 04-29-2008, 1:11 PM
    • Newton-le-Willows, Merseyside, UK
    • Posts 2,575
    • TrustedFriends-MVPs

    Hi Peter, I'll give it a try with Beta 2 in the morning. 

    Steve Big Smile

    Always seeking an elegant solution.
    [Oh! If olny I colud tpye!]
    c# Bits blog
    Oh, and don't forget to mark as answer any posts that help you Big Smile
    Filed under:
  • Re: Having trouble With Minimal Data Attributes working

    11-09-2009, 11:31 AM
    • All-Star
      23,823 point All-Star
    • pkellner
    • Member since 11-12-2004, 10:42 AM
    • San Jose, California
    • Posts 3,579
    • ASPInsiders
      Moderator
      TrustedFriends-MVPs

    Thanks, I think my first problem is to figure out what autogenerate does differently then my dynaniccolumn use 

    Peter Kellner
    http://peterkellner.net
    Microsoft MVP • ASPInsider
  • Re: Having trouble With Minimal Data Attributes working

    11-09-2009, 7:15 PM
    • Star
      12,374 point Star
    • sjnaughton
    • Member since 04-29-2008, 1:11 PM
    • Newton-le-Willows, Merseyside, UK
    • Posts 2,575
    • TrustedFriends-MVPs

    Hi Peter, sorry for not getting back today I called out to sort a Clients machine and wont be back till tomorrow lunch Sad 

    Steve Big Smile

    Always seeking an elegant solution.
    [Oh! If olny I colud tpye!]
    c# Bits blog
    Oh, and don't forget to mark as answer any posts that help you Big Smile
    Filed under:
  • Re: Having trouble With Minimal Data Attributes working

    11-10-2009, 1:50 PM
    • All-Star
      23,823 point All-Star
    • pkellner
    • Member since 11-12-2004, 10:42 AM
    • San Jose, California
    • Posts 3,579
    • ASPInsiders
      Moderator
      TrustedFriends-MVPs

    Still hoping to figure out how to make autogeneratecolumns="false" work for me

    "bump"

    Peter Kellner
    http://peterkellner.net
    Microsoft MVP • ASPInsider
  • Re: Having trouble With Minimal Data Attributes working

    11-12-2009, 5:08 AM
    Answer
    • Star
      12,374 point Star
    • sjnaughton
    • Member since 04-29-2008, 1:11 PM
    • Newton-le-Willows, Merseyside, UK
    • Posts 2,575
    • TrustedFriends-MVPs

    Hi Peter, I have it working in Bets 2, I'll just post my code, I'm using Linq to SQL and standard Metadata but not configuring Dynamic Data in Global.asax.cs.

    Hers' my page:

     <asp:ScriptManager ID="ScriptManager1" runat="server" />
     
     <asp:GridView 
         ID="GridView1" 
         runat="server" 
         AutoGenerateColumns="false"
         AutoGenerateEditButton="true">
         <Columns>
             <asp:DynamicField DataField="ProductName" />
             <asp:DynamicField DataField="QuantityPerUnit" />
             <asp:DynamicField DataField="UnitPrice" />
             <asp:DynamicField DataField="Discontinued" />
         </Columns>
     </asp:GridView>
    


    Just the bits inside the Form and now the code behind:

    public partial class ManualSimpleDD : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            GridView1.EnableDynamicData(typeof(Models.Product));
            var DC = new Models.NWDataContext();
            var products = DC.Products.AsEnumerable();
            GridView1.DataSource = products;
            GridView1.DataBind();
        }
    }
    

    Hope this helps.

    P.S. sorry for the delay in getting back to you I had a client whose PC went down and spent the last few days recovering it Sad

    Steve Big Smile

    Always seeking an elegant solution.
    [Oh! If olny I colud tpye!]
    c# Bits blog
    Oh, and don't forget to mark as answer any posts that help you Big Smile
    Filed under:
Page 1 of 1 (12 items)