Kentico Macro Based on DOM Element

Yoyo Bubble asked on February 22, 2018 22:07


I'm trying to create a macro to be used in a dataLayer element that grabs the value of an id attribute of a DOM element. Such as:

<div class="QuoteForm" id="InsureDirectQualifierA"> Where The div would always have the class QuoteForm

I wanted to create a macro that grabbed the value of the ID element. Maybe something similar to:


Is this possible?


Recent Answers

Peter Mogilnitski answered on February 23, 2018 00:49 (last edited on February 23, 2018 03:52)

You are mixing up a bit server and client things. You id attribute is a client side, macro is a server side. Not quite sure why you want to do it. but you may try something like <'div runat="server" ID="InsureDirectQualifierA" ClientIDMode="Static"> ClientIDMode propertyis used to force controls to generate clean Client IDs, so you can use the id on serverside If you want to grab the value of an form element you can grab from a post back <input type=hidden name="test" value="somevalue"> It also depends where you are trying to get this value, for example if you posting back Kentico form - macro to grab it is simply {%test%}

0 votesVote for this answer Mark as a Correct answer

Yoyo Bubble answered on February 28, 2018 22:46

Awesome! Thanks for the answer.

So quick question, if I add the code to my div as:

<div runat="server" ID="InsureDirectQualifierA" ClientIDMode="Static">

And I'm trying to use a macro that would grab the ID, would I add the name attribute and use that to grab the value, such as:

<div runat="server" ID="InsureDirectQualifierA" ClientIDMode="Static" name="FormVersion">

And then use the macro:


To print the value?

0 votesVote for this answer Mark as a Correct answer

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