Reputation: 6655
I am overriding a Grid, adding some customer features. One of the features is a drop-down to adjust page size. I am extending the grid using a customer server control, which works great for what I've done so far. Now, however I am having a bit of trouble getting the dynamically added control to do a postback. The javascript to initiate the postback is not present.
Protected Overrides Sub OnPreRender(ByVal e As System.EventArgs)
Dim pageSizePanel As New Panel
...
Dim countList As List(Of String) = GetCountList()
Dim pageSizeDropdown As New DropDownList()
pageSizeDropdown.ID = "pageSizeDropdown"
pageSizeDropdown.DataSource = countList
pageSizeDropdown.DataBind()
AddHandler pageSizeDropdown.SelectedIndexChanged, _
AddressOf HandlePageSizeChange
pageSizePanel.Controls.Add(pageSizeDropdown)
...
MyBase.Controls.AddAt(0, pageSizePanel)
MyBase.OnPreRender(e)
End Sub
The HTML is
<select name="tab$grid1Tab$RadGrid1$pageSizeDropdown"
id="tab_grid1Tab_RadGrid1_pageSizeDropdown">
<option selected="selected" value="10">10</option>
<option value="20">20</option>
<option value="40">40</option>
<option value="80">80</option>
<option value="All">All</option>
</select>
So, does this have to do with when I'm 'injecting' the controls? Does it have to do with dynamic addition of the controls?
Upvotes: 1
Views: 600
Reputation: 1613
I think the control pageSizeDropdown would need to be created and the event hooked up earlier in the page lifecycle, see http://msdn.microsoft.com/en-us/library/ms178472.aspx. The dynamically added control needs to be created before the pages LoadComplete event so that its control event can fire.
Upvotes: 1
Reputation: 17501
The first thing I noticed was you'd be missing this:
pageSizeDropdown.AutoPostBack = true
but I'm not sure if that's all you need for it to work
Upvotes: 2
Reputation: 175733
You need to set "AutoPostBack" to true for a dropdown list to postback. Otherwise, another control will have to post the form back (however, the SelectedIndexChanged event will fire when that does happen).
Upvotes: 1