Select the search type
  • Site
  • Web
Search
You are here:  Support/Forums
Support

Bring2mind Forums

Issue creating custom attribute..HELP!!!
Last Post 03/15/2010 9:56 AM by Peter Donker. 7 Replies.
Sort:
PrevPrev NextNext
You are not authorized to post a reply.
Author Messages
GA
New Member
New Member
Posts:40


--
12/05/2008 11:04 PM

Hi,

I am trying to create a custom control..something very simple with just a textbox. I followed the instructions you provided in another topic here but I am running into some problems. I can view the custom control on the custom attributes page, but when I click on the NEXT button, I see the message

Value cannot be null. Parameter name: key

This is all I have added in the controls code in WriteToCurrentEntry function

Dim

bExists As Boolean

 

 

 

Dim att As AttributeInfo = AttributesController.FindAttributeByName("SimpleControl", PortalId)For Each eatt As EntryAttributeInfo In EntryToUpdate.CustomAttributesIf eatt.AttributeId = att.AttributeId Then

eatt.Value = txtSimple.Text

bExists =

True

 

End If

 

Next

 

If Not bExists Then

 

 

.AttributeId = att.AttributeId

.EntryId =

.Value = txtSimple.Text

 

Dim eatt As New EntryAttributeInfoWith eattMe.EntryIdEnd With

EntryToUpdate.CustomAttributes.Add(eatt)

 

End If

Why is this happening. Please help or could someone post the instructions or code for creating a simple custom control.

When I debug, this is what I get

System.ArgumentNullException was caught
  Message="Value cannot be null. Parameter name: key"
  ParamName="key"
  Source="mscorlib"
  StackTrace:
       at System.ThrowHelper.ThrowArgumentNullException(ExceptionArgument argument)    at System.Collections.Generic.Dictionary`2.Insert(TKey key, TValue value, Boolean add)    at Bring2mind.DNN.Modules.DMX.Business.EntryAttributesCollection.Add(EntryAttributeInfo value)    at Bring2mind.DNN.Modules.DMX.SimpleControl.WriteToCurrentEntry(EntryInfo& EntryToUpdate) in C:\Documents and Settings\george_a.SUBWAYDAI\My Documents\DOCS\DMX\DMX 5\Resources\Controls\SimpleControl.ascx.vb:line 33    at Bring2mind.DNN.Modules.DMX.Controls.WebControls.CustomAttributes.WriteToCurrentEntry(EntryInfo& EntryToUpdate)    at Bring2mind.DNN.Modules.DMX.Controls.EditEntry.HandleWizardStep(Control StepContent) in C:\Documents and Settings\george_a.SUBWAYDAI\My Documents\DOCS\DMX\DMX 5\Resources\EditEntry.ascx.vb:line 338    at Bring2mind.DNN.Modules.DMX.Controls.EditEntry.ChangePage(Object sender, WizardNavigationEventArgs e) in C:\Documents and Settings\george_a.SUBWAYDAI\My Documents\DOCS\DMX\DMX 5\Resources\EditEntry.ascx.vb:line 243
  InnerException:
 

I have already spent a lot of time to figure this out and it would be really helpful if there was some documentation on this.

Thanks

 

GA
New Member
New Member
Posts:40


--
12/08/2008 3:11 PM

Hello....I really need to figure out what this issue is. Any help would be appreciated.

I forgot to add that I am running DMX 5 on dnn4.9. Also the code I posted doesnt look right, so here is the actual code.

Dim bExists As Boolean
        Dim att As AttributeInfo = AttributesController.FindAttributeByName("SimpleControl", PortalId)
        For Each eatt As EntryAttributeInfo In EntryToUpdate.CustomAttributes
            If eatt.AttributeId = att.AttributeId Then
                eatt.Value = txtSimple.Text
                bExists = True
            End If
        Next
        If Not bExists Then
            Dim eatt As New EntryAttributeInfo
            With eatt
                .AttributeId = att.AttributeId
                .EntryId = Me.EntryId
                .Value = txtSimple.Text

            End With
            EntryToUpdate.CustomAttributes.Add(eatt)
        End If

Peter Donker
Veteran Member
Veteran Member
Posts:4536


--
12/08/2008 10:20 PM
Hi,

As it happens I'm working on a custom project right now with this kind of implementation. The code you've got looks good. I used a slightly different version of this so you might try this:

Public Overrides Sub WriteToCurrentEntry(ByRef EntryToUpdate As DMX.Business.EntryInfo)

Dim ea As New EntryAttributeInfo
For Each ea In EntryToUpdate.CustomAttributes
If ea.AttributeId = MyAttId Then
EntryToUpdate.CustomAttributes.Remove(ea)
End If
Next
ea = New EntryAttributeInfo
With ea
.AttributeId = MyAttId
.EntryId = Me.EntryId
.Value = ddContract.SelectedValue
End With
EntryToUpdate.CustomAttributes.Add(ea)

End Sub

Where MyAttId is the integer of the AttributeID (I store and cache it in a settings class). I'm working on 05.00.01. Note that you have to reference DMX 5 dlls and not DMX 4 in your project.

Peter

GA
New Member
New Member
Posts:40


--
12/10/2008 7:38 PM
Hi Peter,

Thanks for the reply.

I actually solved it by using the constructor when creating a new EntryAttributeInfo. I am not sure why. The only extra piece of information in the constructor was the portalID.

I am a bit confused on the way in which I should go about custom attributes and I am hoping you can clear it up for me.
Right now, I am adding a new User Control for my custom attribute in the DMX code and building a new dll which would then include it. However this would mean that each time I need a custom attribute (User Control), I would need to compile the DMX dll which I do not want to do.

I also read in your blog on creating custom attributes that we could do this as an add-on and I am not sure how that goes. Does that mean that I can create a seperate project which would hold all my custom attributes which are User Controls and then make that project an add-on. If I can do this, I would just need to build this dll if I need to add a new User Control. Can it be done this way.

Do you have any pointers on this.

Thanks

Peter Donker
Veteran Member
Veteran Member
Posts:4536


--
12/11/2008 8:37 PM
Hi AG,

An addon is just like a regular module. You install ascx files and dlls like a module. In the DMX_Attributes table the definitions of the attributes are stored. You can add to this through an SQL script. This is what you would do when creating an addon. Because it is just like a module, DNN will run those scripts for you upon install. In the DB you set the path to the control for the attribute. And your control gets loaded. Even though the codebehind is in your own dll. It doesn't matter. Your project references DMX and you compile your own dll. I guess it is second nature to me now as I'm a module developer, but this is how all precompiled modules do it. We just reference the core DNN framework. For a DMX addon you reference DMX as well.

Peter
GA
New Member
New Member
Posts:40


--
12/12/2008 8:12 PM
Thanks
samstar
New Member
New Member
Posts:1


--
02/22/2010 9:15 AM
Hi

I used the code above for creating a custom attribute in the dmx module, but i faced some problems please help me in solving them.
1-This code is only for a usercontrol with one element (textbox), what about if we need to have more ? How should we change the code ?
2-I couldnt find "FindAttributeByName" method and i used "FindAttributeByKey" instead, does it make problem ?

Thanks in advance
Peter Donker
Veteran Member
Veteran Member
Posts:4536


--
03/15/2010 9:56 AM
Hi Sam,

1. Actually since the control is isolated in itself, you can pretty much do anything you want. If you want to add more boxes it is not a problem. If you want to manage more custom attributes that way you just set the other attributes to be "Private" (see the DMX_Attributes table) so they don't get rendered by DMX. Then you just manage them yourself in your code.

2. Yes, the new method is "Key". Since DMX 5.1 the "Name" of the attribute has been moved into the ShortTexts table and you now use the column KEY to look for it.

Peter
You are not authorized to post a reply.