Html helpers

3 posts, 0 answers
  1. MiBu
    MiBu avatar
    7 posts
    Member since:
    Aug 2012

    Posted 19 Jun 2012 Link to this post

    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. Matt
    Matt avatar
    1 posts
    Member since:
    Jul 2012

    Posted 03 Jul 2012 Link to this post

    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....
  3. UI for ASP.NET MVC is VS 2017 Ready
  4. Matt
    Matt avatar
    1 posts
    Member since:
    Jul 2012

    Posted 10 Jul 2012 Link to this post

    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.
Back to Top