I have a macro, that renders a contact formular. If the user insert the macro several times on the page, I want to give each macro a unique id for their input-fields, so that my javascript code know which input-field to check.
I put two macros per Grid-Insert Macro Selector on the page.
Both macros render with the same random Integer. Cache for the macro is not activated of course.
So did I do something wrong or is it an umbraco-performance issue, that same macro-source is only rendered once?
@functions
{
public int getRandomNumber()
{
Random rnd = new Random((int)DateTime.Now.Ticks);
int RandomNumber;
RandomNumber = rnd.Next(100000, 999999);
return RandomNumber;
}
}
Random Integer Value in PartialView Macro
Hi,
I have a macro, that renders a contact formular. If the user insert the macro several times on the page, I want to give each macro a unique id for their input-fields, so that my javascript code know which input-field to check.
I thought this would be very easy:
I put two macros per Grid-Insert Macro Selector on the page. Both macros render with the same random Integer. Cache for the macro is not activated of course.
So did I do something wrong or is it an umbraco-performance issue, that same macro-source is only rendered once?
OK, Why don't you create a helper class to handle this. Something like this:
and call it from your view
Hi Streety,
thanks for the hint.
This one does the trick:
is working on a reply...