Dynamically added control does not postback

I am overriding Grid by adding some client functionality. One of the features is a dropdown box for adjusting the page size. I am expanding the grid with a client server which works great for what I have done so far. Now, however, I'm a bit at a loss to get the dynamically added control to do the postback. There is no Javascript to initiate postbacks.

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

      

Html

<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 it have to do with when I "inject" the controls? Does it have to do with adding controls dynamically?

+1


source to share


3 answers


The first thing I noticed it would be wrong:

pageSizeDropdown.AutoPostBack = true

      



but i'm not sure if all you need to work

+2


source


You need to set "AutoPostBack" to true for the postback dropdown. Otherwise, another control will have to submit the form back (however, the SelectedIndexChanged event will fire when it does).



+1


source


I think it will be necessary to create a SizeDropdown control page and an event linked earlier in the page lifecycle see http://msdn.microsoft.com/en-us/library/ms178472.aspx . A dynamically added control must be created before the LoadComplete event is loaded in order for its control event to fire.

+1


source







All Articles