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?
partial class IT_Servers : IAuditable
{
public class Metadata
{
[ScaffoldColumn(false)]
public object Id;
public object ServerName;
}
[DynamicDataWebMethod]
public void TurnOffPower()
{
VirtualServerSDK.PowerOff(ServerName);
}
}
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?
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).
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.
See my blog C# Bits | Twitter @sjnaughton Always seeking an elegant solution.
tsoft
0 Points
6 Posts
How can I get the Entity Object in an Edit page event using Dynamic Data?
Apr 10, 2012 10:01 PM|LINK
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
tsoft
0 Points
6 Posts
Re: How can I get the Entity Object in an Edit page event using Dynamic Data?
Apr 10, 2012 10:33 PM|LINK
Can I get the EntityObject somehow in the Page_Init or Page_Load events?
tsoft
0 Points
6 Posts
Re: How can I get the Entity Object in an Edit page event using Dynamic Data?
Apr 10, 2012 10:43 PM|LINK
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); } }TimoYang
Contributor
3732 Points
1275 Posts
Re: How can I get the Entity Object in an Edit page event using Dynamic Data?
Apr 12, 2012 01:27 AM|LINK
Please handle the FormView_ItemDataBound and you can get the DataItem through the parameter of "e",which is auto-generated……
tsoft
0 Points
6 Posts
Re: How can I get the Entity Object in an Edit page event using Dynamic Data?
Apr 12, 2012 02:11 AM|LINK
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?
TimoYang
Contributor
3732 Points
1275 Posts
Re: How can I get the Entity Object in an Edit page event using Dynamic Data?
Apr 12, 2012 02:12 AM|LINK
Plz re-databind to the DataSource of the FormView again when rendering the page or in the Page_Load event do that……
tsoft
0 Points
6 Posts
Re: How can I get the Entity Object in an Edit page event using Dynamic Data?
Apr 12, 2012 02:15 AM|LINK
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).
TimoYang
Contributor
3732 Points
1275 Posts
Re: How can I get the Entity Object in an Edit page event using Dynamic Data?
Apr 12, 2012 07:01 AM|LINK
Why?Show us your codes……
sjnaughton
All-Star
27308 Points
5458 Posts
MVP
Re: How can I get the Entity Object in an Edit page event using Dynamic Data?
Apr 12, 2012 01:13 PM|LINK
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.
Always seeking an elegant solution.