If GridView (rendered as a table) is within the div then the div cannot be smaller than the GridView. The problem is that the resize handle is being placed in the wrong spot by the JavaScript associated with the ResizeControlExtender. This happens if you haven't set the height and width css style for the panel.
The following code has been tested and works properly:
Imports AjaxControlToolkit
Public Class Resizer
Inherits Panel
Private _resizeExtender As ResizableControlExtender
Private _grid As GridView
Private _contentContainer As Panel
Private Sub Resizer_Init(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Init
_contentContainer = New Panel
_contentContainer.ID = Me.ClientID + "contentContainer"
_contentContainer.Style.Add("height", "50px")
_contentContainer.Style.Add("width", "50px")
_contentContainer.Style.Add("overflow", "auto")
_contentContainer.Style.Add("border", "solid 1px black")
_grid = New GridView
_grid.ID = Me.ClientID + "grid"
_grid.DataSource = CreateSource()
_grid.DataBind()
_contentContainer.Controls.Add(_grid)
_resizeExtender = New ResizableControlExtender
_resizeExtender.MinimumHeight = 50
_resizeExtender.ID = Me.ClientID + "resizeExtender"
_resizeExtender.HandleCssClass = "resizingImage"
_resizeExtender.TargetControlID = _contentContainer.ID
Me.Controls.Add(_contentContainer)
Me.Controls.Add(_resizeExtender)
End Sub
Private Function CreateSource() As DataView
Dim sourceTable As New DataTable
sourceTable.Columns.Add("column 1")
sourceTable.Columns.Add("column 2")
sourceTable.Columns.Add("column 3")
For i As Integer = 0 To 20
Dim row As DataRow = sourceTable.NewRow
row("column 1") = "col1 " + i.ToString
row("column 2") = "col2 " + i.ToString
row("column 3") = "col3 " + i.ToString
sourceTable.Rows.Add(row)
Next
Return New DataView(sourceTable)
End Function
End Class
To get this to work all I did was add a style to the Panel containing the GridView. The style sets the initial height and width and the ResizeControlExtender is properly placed in the bottom left corner.
The JavaScript I used for resizing was taken directly out of the AjaxToolkit Example project:
<script type="text/javascript">
function OnClientClickGrow() {
var rcp = $find('ResizableControlBehavior1');
var size = rcp.get_Size();
rcp.set_Size({ width: size.width * 2, height: size.height * 2 });
return false;
}
var fontSize = 12;
function OnClientResizeText(sender, eventArgs) {
// This sample code isn't very efficient, but demonstrates the idea well enough
var e = sender.get_element();
// Make the font bigger until it's too big
while ((e.scrollWidth <= e.clientWidth) || (e.scrollHeight <= e.clientHeight)) {
e.style.fontSize = (fontSize++) + 'pt';
}
var lastScrollWidth = -1;
var lastScrollHeight = -1;
// Make the font smaller until it's not too big - or the last change had no effect
// (for Opera where e.clientWidth and e.scrollWidth don't behave correctly)
while (((e.clientWidth < e.scrollWidth) || (e.clientHeight < e.scrollHeight)) &&
((Sys.Browser.agent !== Sys.Browser.Opera) || (e.scrollWidth != lastScrollWidth) || (e.scrollHeight != lastScrollHeight))) {
lastScrollWidth = e.scrollWidth;
lastScrollHeight = e.scrollHeight;
e.style.fontSize = (fontSize--) + 'pt';
}
}
</script>
-Frinny