Portal Engine Questions on portal engine and web parts.
Version 4.x > Portal Engine > CustomEventHandler OnBeforeInsert Question View modes: 
User avatar
Member
Member
agerace-ag.state.oh - 12/1/2009 10:39:04 AM
   
CustomEventHandler OnBeforeInsert Question
What do I cast the DataObject to?

It seems sometimes its a SimpleDataClass sometimes its a DataClass, if I don't have the right one I get invalid cast.

How should I be accessing the DataObject in the CustomEventHandler OnBeforeInsert method?


User avatar
Member
Member
agerace-ag.state.oh - 12/1/2009 12:56:43 PM
   
RE:CustomEventHandler OnBeforeInsert Question
Never mind I figured it out.

Here it is in case anyone else is interested.

 
//Get the Type
Type T = dataObj.GetType();

if (T.Name == "SimpleDataClass")
{
SimpleDataClass InsertDataObject = (SimpleDataClass)dataObj;
if (InsertDataObject.ClassName == "Forums.ForumPost")
//Do what you want with a new forum post.
}



User avatar
Kentico Developer
Kentico Developer
kentico_zbysekn - 12/1/2009 2:00:20 PM
   
RE:CustomEventHandler OnBeforeInsert Question
Hello,
yes this should be good solution how you can handle this kind of data.
Thank you for posting the example.
Best Regards,
Zbysek Nemec.

User avatar
Member
Member
Scott - 1/20/2010 11:41:16 PM
   
RE:CustomEventHandler OnBeforeInsert Question
You can possibly also cast it as IDataClass, which both DataClass and SimpleDataClass implement -- depends on what you need, but if you just need the interface methods, it's easier that checking the type.

User avatar
Member
Member
Scott - 1/20/2010 11:47:52 PM
   
RE:CustomEventHandler OnBeforeInsert Question
Is there any documentation describing when it will be a DataClass or when it will be a SimpleDataClass? What is the difference between the two?

User avatar
Kentico Developer
Kentico Developer
kentico_martind - 1/21/2010 8:55:48 AM
   
RE:CustomEventHandler OnBeforeInsert Question
Hi Scott,

Regrettably, this is not described in documentation. The solution is described in DataObj parameter in CustomHandler seems to be of type SimpleDataClass not DataClass article. Basically the SimpleDataClass class is more efficient as it doesn't store data in DataRow and it is used by default, but sometimes there is DataRow required so in this case the DataClass object is used as it contains data in DataRow.

Best Regards,

Martin Dobsicek