Actually having two questions that are closely related:
Is it possible to bind a resource in markup file (.dothtml / .dotcontrol) inside a dot:InlineScript control? It seems not. If indeed not possible, how to work around this? Reverting to simple <script> HTML tags is bad, complicating things a lot.
The broader question: how to properly migrate blocks of JS that are filled with server tags feeding control client ids into the JS and avoid hard coding ids?
Of course we want to change the legacy JS as little as possible as to avoid cost impacts on the migration efforts. Restructuring it is out of the question - too costly, we have many situations like this example that implement various custom front-end functional/UI-UX extensions to the WebForms controls.
(1) Yes, you most likely want to use the value from the view model (you can use dotvvm.state.MyProperty to avoid knockout observables). If you’d really need to place constants into JS string, you can create the script in the view model and use
The resource binding inside the <script> tag does not escape for use in JavaScript, which may lead to XSS bugs if the inserted string can be controlled by the user.
(2) I don’t know, maybe @tomasherceg has some guidance. If it’s a page where the ids are the same, I’d probably just inline the constant IDs for the transition (copy the generated JS from the browser instead from the aspx file)
(1) Interesting and I will keep this variant in mind. Unfortunately, it is an anti-pattern in our project (JS code must stay in the markup file).
And yes, I try to keep as far away as possible from wrapping the migrated JS code into simple <script> blocks.
(2) I really miss the comfort and productivity of what WebForms permitted (see the “trick” in earlier post) by using in front-end JS/jquery selectors, the client ids of the controls (no hardcoding and if changes or refactoring happened - the references would fail with red underline in the editor - which is evidently a big plus in time for the maintenance aspect of the project)
I think this suggestion would limit me to “hard code” the client IDs. @tomasherceg What do you think?