ASP.NET MVC View ReRenders Part of Itself
- by Jason
In all my years of .NET programming I have not run across a bug as weird as this one. I discovered the problem because some elements on the page were getting double-bound by jQuery. After some (ridiculous) debugging, I finally discovered that once the view is completely done rendering itself and all its children partial views, it goes back to an arbitrary yet consistent location and re-renders itself.
I have been pulling my hair out about this for two days now and I simply cannot get it to render itself only once!
For lack of any better debugging idea, I've painstakingly added logging tracers throughout the HTML just so I can pin down what may be causing this. For instance, this code ($log just logs to the console):
...
<script type="text/javascript">var x = 0; $log('1');</script>
<div id="new-ad-form">
<script type="text/javascript">x++;$log('1.5', x);</script>
...
will yield
... <--- this happens before this snippet
1
1.5 1
...
10 <--- bottom of my form, after snippet
1.5 2 <--- beginning of part that runs again!
...
9 <--- this happens after this snippet
I've searched my codebase high and low, but there is NOTHING that says that it should re-render part of a page. I'm wondering if the jQueryUI has anything to do with it, as #new-ad-form is the container for a jQueryUI dialog box.
If this is potentially the case, here's my init code for that:
$('#new-ad-form').dialog({
autoOpen: false,
modal: true,
width: 470,
title: 'Create A New Ad',
position: ['center', 35],
close: AdEditor.reset
});