CodeName form control

Brenden Kehren asked on February 13, 2015 07:14

I'm using the code name form control and want to change the default replacement for an invalid code name character, where can this be done? I was thinking it would use the Forbidden characters replacement setting but it doesn't. And I'm not seeing anything in the actual from control. Ideally I want it to be a dash ( - ) vs an underscore ( _ ).

Correct Answer

Radek Macalik answered on April 29, 2015 08:46


This replacement could be done for example in the WebPartCategoryInfo.TYPEINFO.Events.Insert.Before event. Or, in general, you could use any proper object event handler as described here.

For the WebPartCategoryInfo.TYPEINFO.Events.Insert.Before event, the logic could look like this:

WebPartCategoryInfo.TYPEINFO.Events.Insert.Before += WebPartCategoryInfo_Insert_Before;

        private void WebPartCategoryInfo_Insert_Before(object sender, ObjectEventArgs e)
            if (e.Object != null)
                // no object provided

            var webPartCategory = (WebPartCategoryInfo)e.Object;
            webPartCategory.CategoryName = webPartCategory.CategoryName.Replace("_", "-");

Hope it helps.

Best regards,

Radek Macalik , Kentico support

0 votesVote for this answer Unmark Correct answer

   Please, sign in to be able to submit a new answer.