This is a migrated thread and some comments may be shown as answers.

Html helpers

2 Answers 173 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
MiBu
Top achievements
Rank 1
MiBu asked on 19 Jun 2012, 10:07 AM
Hi,

MVC controls helpers generated html, then on the end with ScriptRegistrar applied javascript to those elements. Now you are rendering script just after the element, so if I have 100 controls on page, 100 script "oneliners" would appear in generated html(both examples below).

Question is why change helpers behaviour(except initializanig control properties through jquery)? 

old way:

    <div class="t-widget t-dropdown t-header" style="width:100%;" tabindex="0"><div class="t-dropdown-wrap t-state-default"><span class="t-input">Value</span><span class="t-select"><span class="t-icon t-arrow-down">select</span></span></div><input id="someField" name="someField" style="display:none" type="text" value="0"></div>
//scripts are applied on the end with ScriptRegistrar, so clean html, no matter how much controls



new way

<span style="" class="k-widget k-combobox k-header"><span unselectable="on" class="k-dropdown-wrap k-state-default"><input class="k-input" type="text" autocomplete="off" tabindex="0" style="width: 100%; "><span unselectable="on" class="k-select"><span unselectable="on" class="k-icon k-arrow-down">select</span></span></span><input id="someField" name="someField" data-role="combobox" style="display: none; "></span><br><br><script><br><span class="Apple-tab-span" style="white-space:pre"> </span>

//this part bothers me, with each control I get this in html
<script>jQuery(function(){jQuery("\#someField").kendoComboBox({});});
</script>

2 Answers, 1 is accepted

Sort by
0
Matt
Top achievements
Rank 1
answered on 03 Jul 2012, 02:39 PM
I'd also be interested in the rationale - I think I did read some reasoning behind the abandonment of ScriptRegistrar somewhere but I can't remember where....
0
Matt
Top achievements
Rank 1
answered on 10 Jul 2012, 02:28 PM
There is another discussion here regarding some of the rationale, however this is acutally more of a problem than it first seems. It appears that no consideration has been given to what happens if you modify the DOM once the page has loaded. I have some code that does just this. It uses jQuery to wrap certain elements and because those elements are effectively removed and reinserted into the DOM the associated script snippet (inserted by Kendo) is re-run by the browser, causing the kendo control to be initialized twice. It doesn't take too kindly to this, and it falls over and dies. It also appears to cause problems with initial value binding of the editor. Because the body is within an iframe, reinserting it causes the iFrame to reload (I think this is specifically related to a mozilla bug). Loading scripts at the end of the body (i.e. how it used to work with the old Telerik extensions) would afford us the option of running our scripts before or after Kendo scripts, thus avoiding these issues.
Tags
General Discussions
Asked by
MiBu
Top achievements
Rank 1
Answers by
Matt
Top achievements
Rank 1
Share this question
or