Note that there are some explanatory texts on larger screens.

plurals
  1. POhow to Resize child list box height in asp.net User control
    primarykey
    data
    text
    <p>Given the following User control markup: </p> <pre><code>&lt;%@ Control Language="C#" AutoEventWireup="true" CodeFile="SearchItem.ascx.cs" Inherits="MyWeb.controls.SearchItem" %&gt; &lt;div id="container" runat="server" style="height: 100%; width: 100%;"&gt; &lt;div&gt; &lt;asp:Label ID="lblSearch" runat="server" Text="Search:"&gt;&lt;/asp:Label&gt; &lt;br /&gt; &lt;asp:TextBox ID="txtSearch" runat="server"&gt;&lt;/asp:TextBox&gt; &lt;input id="btnSearch" type="button" value="Search" onclick="SearchClick(this)" /&gt; &lt;/div&gt; &lt;div&gt; &lt;asp:Label ID="lblItems" runat="server" Text="Available Items:"&gt;&lt;/asp:Label&gt; &lt;/div&gt; &lt;div id="itemContents" runat="server" style="min-height: 50%; width: 100%;border: 1px solid black;"&gt; &lt;asp:ListBox ID="lbxResults" runat="server" SelectionMode="Single" Width="100%" AutoPostBack="True"&gt;&lt;/asp:ListBox&gt; &lt;/div&gt; </code></pre> <p></p> <p>I would like the user control height to be equal to placeholder height with list box to grow and fill up any height difference as all other controls are of known size. Some useful info:</p> <ul> <li><p>Height can have the following values: 300, 400, 600 px, thus the need for the listbox height to compensate for any height difference. </p></li> <li><p>List box can contain 0 to 2000 elements.</p></li> <li><p>Placeholder can be a div or an asp.net tab container.</p></li> </ul> <p>For testing purposes, I did:</p> <ol> <li><p>Create a new user control, eg. SearchItem.ascx </p></li> <li><p>Create a default aspx page for example:</p></li> </ol> <p>a) Add the user control //&lt;%@ Register TagPrefix="uc" TagName="SearchItem" Src="~/Controls/SearchItem.ascx" %></p> <p>b) Add to body</p> <pre><code> &lt;form id="form1" runat="server"&gt; &lt;div id="ChangeMyHeight" style="height: 300px; width: 30%; float: left;"&gt; &lt;uc:SearchItem ID="AvailableItems" runat="server"&gt; &lt;/uc:SearchItem&gt; &lt;/div&gt; &lt;/form&gt; </code></pre> <p>Now if you change the height of the container div to 500, 600.(ChangeMyHeight), you will have:</p> <p>Current behaviour:</p> <ul> <li>Listbox is not resizing properly. (filling the height difference)</li> </ul> <p>Expected behaviour:</p> <ul> <li>Listbox is resizing properly and filling the height difference. (like docking in Winforms) </li> </ul> <p>My preference would be a css/jquery solution but code behind will do as well (I was thinking of using a height property to set up the child controls)</p> <p>Notes:</p> <ol> <li>The sample markup uses style for brevity's sake.</li> <li>The sample markup has hard coded some values for demo purposes(thus the demo is working for height 300 px but not for the other values), feel free to change style/html as needed.</li> <li>Environment: VS2010/.NET 4.0/jQuery latest.</li> <li>Browsers: FF, IE7/8/9</li> </ol>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload