locked
How can I get the Entity Object in an Edit page event using Dynamic Data? RRS feed

  • Question

  • User182634413 posted

    Hopefully this is a simple question. Here's what I am trying to do:

    1. Add table/entityobject specific buttons to the Edit.aspx page in the Dynamic Data framework. (I will do this by reflecting the type and creating buttons for all methods marked "DynamicDataWebMethod")

    2. Add these buttons during Page_Init so the OnClick event triggers.

    3. In my OnClick event, How can I get the FormView DataItem? The DataItem that inherits from EntityObject? When I get into the OnClick method the FormView1 has not been bound yet. How can I force it to be bound? Is there another way to get the EntityObject?

    I just need help with #3. :)

    Thanks in advance!
    Mitch

    Tuesday, April 10, 2012 6:01 PM

All replies

  • User182634413 posted

    Can I get the EntityObject somehow in the Page_Init or Page_Load events?

    Tuesday, April 10, 2012 6:33 PM
  • User182634413 posted

    Just for fun here is a mock up of my data class:

    partial class IT_Servers : IAuditable
    {
         public class Metadata
         {
              [ScaffoldColumn(false)]
              public object Id;
    
              public object ServerName;
         }
    
         [DynamicDataWebMethod]
         public void TurnOffPower()
         {
              VirtualServerSDK.PowerOff(ServerName);
         }
    }



    Tuesday, April 10, 2012 6:43 PM
  • User-1488931086 posted

    How can I get the FormView DataItem?

    Please handle the FormView_ItemDataBound and you can get the DataItem through the parameter of "e",which is auto-generated……

    Wednesday, April 11, 2012 9:27 PM
  • User182634413 posted

    Timo, Thank you for the idea but I don't think it will work due to the way the page life-cycle works.

    The problem is that I am trying to access the DataItem from the OnClick event of a LinkButton. When this event is being triggered the FormView.DataItem is null.

    Isn't there a way to get the EntityObject in the Page_Init or Page_Load events?

    Wednesday, April 11, 2012 10:11 PM
  • User-1488931086 posted

    Plz re-databind to the DataSource of the FormView again when rendering the page or in the Page_Load event do that……

    Wednesday, April 11, 2012 10:12 PM
  • User182634413 posted

    I have tried to call FormView.DataBind() from the Page_Load event as you suggested and it fails. How do you trigger it?

    If I call DataBind() in OnClick it does indeed bind and I can work with the DataItem object.. This a step in the right direction but I need to access it earlier.

    Is there a way to get the EntityObject from the MetaTable "table" object? I tried reflecting it and could not find the DataItem (though I could find the Type.. but I'd like access to the column values so I can make design decisions).

    Wednesday, April 11, 2012 10:15 PM
  • User-1488931086 posted

    I have tried to call FormView.DataBind() from the Page_Load event as you suggested and it fails.

    Why?Show us your codes……

    Thursday, April 12, 2012 3:01 AM
  • User-330204900 posted

    Hi Tsoft, what is it you are trying to achive, with DD it's somtimes better to descibe what it is you want o achive, as there are often simpler or beter way to do things in DD.

    Thursday, April 12, 2012 9:13 AM