Portal Engine Questions on portal engine and web parts.
Version 7.x > Portal Engine > Setting the RelationshipWithNodeGuid property of a nested repeater View modes: 
User avatar
Member
Member
Jerreck - 1/15/2014 6:27:55 PM
   
Setting the RelationshipWithNodeGuid property of a nested repeater
I was creating a transformation earlier today where I had to define the RelationshipWithNodeGuid property of a cms:repeater nested within a Smart Search Results web part. The code looked something like this:
<script runat="server">
protected override void OnInit(EventArgs e)
{
If(!IsPostBack) {
base.OnInit(e);
WebPartID.RelationshipWithNodeGuid = (Guid)GetSearchValue("NodeGUID");
}
}
</script>

This worked just fine, until I also had to use a Smart Search Filter with the Smart Search results web part - which caused a post back to occur anytime you selected a condition to filter your search results. After the post back, the script would return false, so it would not set the RelationshipWithNodeGuid property of that nested repeater.

I figured the following would take care of that problem:
<script runat="server">
protected override void OnInit(EventArgs e)
{
base.OnInit(e);
WebPartID.RelationshipWithNodeGuid = (Guid)GetSearchValue("NodeGUID");
}
</script>

However, this caused an exception upon postback:
Object not set to an instance of an object

I'm pretty new to C# and ASP.NET (surprise!), so I wasn't exactly sure why I was getting this error. My manager suggested I try the following:
<script runat="server">
protected override void OnInit(EventArgs e)
{
If(GetSearchValue("NodeGUID") != null) {
base.OnInit(e);
WebPartID.RelationshipWithNodeGuid = (Guid)GetSearchValue("NodeGUID");
}
}
</script>

This worked just perfectly, but neither of us were 100% certain why this solution worked as opposed to what I was trying. Would anyone care to explain what the problem was?

User avatar
Kentico Support
Kentico Support
kentico_janh - 2/5/2014 3:25:58 AM
   
RE:Setting the RelationshipWithNodeGuid property of a nested repeater
Hello,

Actually, not all results within the search are document types (it finds also custom tables or objects like users, et.c), and NodeGUID is available only for documents, so that's why you are getting that error and you need to check if it is not null before you use it.

Best regards,
Jan Hermann