Accessing Custom Attributes of Widgets from Codebehind

Posted by Community Admin on 03-Aug-2018 15:41

Accessing Custom Attributes of Widgets from Codebehind

All Replies

Posted by Community Admin on 23-Jan-2015 00:00

Hi,

 I adapted the "News" library to allow the user to attach media files to the NewsItem.

I created a widget template to display the news item (and news list). Rendering of the news items works fine. Now I want to query the model in code behind to see whether any news were attached or not.

((Telerik.Sitefinity.News.Model.NewsItem)((Telerik.Web.UI.RadListViewDataItem)(e.Item)).DataItem)

I am able to navigate to the NewsItem (with the above code). I am seeing the Content of the NewsItem there but I don't see the custom attributes. Any hints?

 

Thanks,

/Kay

Posted by Community Admin on 23-Jan-2015 00:00

Do you mean like custom fields?  They are defined in the DB, not part of the physical object  so visual studio can't show you them...however they are still there (if this is what you mean)

 Just use the syntax of .GetValue<type>("fieldname")

 If you don't see getvalue make sure you have Telerik.Sitefinity, Telerik.Sitefinity.Model in your usings.

Posted by Community Admin on 26-Jan-2015 00:00

Thanks, Steve.

I wasn't aware that "GetString" were extension methods. Indeed I didn't include the necessary namespaces.

This thread is closed