Jquery dialog resizing only happens the first time it's opened
<p>I have this code for a JQuery a dialog for a div containing a gridview that loads with a lists of tasks. The dialog fits to the contents OK, but if hundreds of tasks are loaded the dialog gets too big and can't be resized by hand, so I needed to code a way for it to open with a manageable size.</p>

<p>Before anyone suggests it, <strong>I tried setting the max-height property on my div to 500px</strong> and that worked fine except the div wouldn't fill the whole dialog if the dialog got higher than 500px, which we want it to. <strong>I also tried setting the maxHeight property on the dialog</strong> directly but that only takes effect when you resize the dialog by hand, not when the dialog opens. And when the dialog opens bigger than the screen that can't be done.</p>

<p>So instead I wrote this code which declares the dialog, then if more than 20 tasks are loaded the dialog is supposed to be resized to 500px high. That way the div inside fills the dialog completely at all times and the dialog size stays managable.</p>

<pre><code>function ShowReferedTasks(title, s, taskCount) {

    //On crée le dialog à partir de la même div       
    $('#litReferedTasks').dialog({
        autoOpen: true,
        modal: true,
        resizable: true,
        show: 'drop',
        hide: 'drop',
        width: 800,
        minHeight: 0,
        title: 'Tâche' + s + ' référée' + s + ' de ' + title
    });

    //if more than 20 refered tasks are found
    if (taskCount &gt; 20) {        
        $('#litReferedTasks').dialog('option', 'height', 500);
        $('#litReferedTasks').dialog('option', 'position', 'center');
    }
}
</code></pre>

<p>This code is called from a button in each line of a parent gridview, loading each line's tasks.</p>

<p>Here is what happens when I refresh my page and flush the cache (ctrl+F5), then open some task lists.</p>

<ol>
<li><p>If I open one list of tasks containing more than 20 tasks (a dialog that will need to be refreshed), <strong>it works fine</strong>.</p></li>
<li><p>If I open any list of tasks, even one with less than 20 tasks that doesn't need resizing, then close it, and open one with more than 20 tasks, <strong>the dialog opens and the gridview is filled perfectly but the resizing doesn't work</strong>, the dialog is too big to fit on the screen, and can't be resized by hand.</p></li>
</ol>

<p>Basically the resize part of my code only works on the first dialog I open after refreshing my page and flushing the cache. I think something must be kept in memory after the first time a dialog is opened, but I'm a newbie with JQuery and JS in general and I can't find the answer.</p>

<pre class="lang-html prettyprint-override"><code>&lt;div id="litReferedTasks" style="background-color: White; display: none; overflow:auto; height:95%;"&gt;
    &lt;asp:GridView ID="gvReferedTasks" runat="server" OnRowDataBound="gvReferedTasks_RowDataBound" Width="97.5%" Visible="false"&gt;        
    &lt;/asp:GridView&gt;
    &lt;asp:Label ID="lblNoReferedTasks" runat="server" Visible="false" Width="100%"&gt;&lt;/asp:Label&gt;
&lt;/div&gt;
</code></pre>

<p>Any help?</p>
