0

I've a user control contined in MyPage.aspx. The user control contains few drop-down lists; each with Autopostback = true but when I run the code & change the drop-down item, other events gets fired but not SelectedIndexChanged.

<asp:DropDownList ID="ddPages1" runat="server" EnableViewState="true" AutoPostBack="true"
    onselectedindexchanged="ddPages1_SelectedIndexChanged">
</asp:DropDownList>

Code behind of ascx:

protected void ddPages1_SelectedIndexChanged(object sender, EventArgs e)
{
    ...
}

ascx also has ReportViewer & I'm populating number of pages in the report into drop-down list.

protected override void Render(HtmlTextWriter writer)
{
    TotalPages = ReportViewer1.LocalReport.GetTotalPages();
    txtPageCount1.Text = Convert.ToString(TotalPages);
    if (TotalPages > 0)
    {
        for (int i = 1; i <= TotalPages; i++)
        {
            ListItem listItem = new ListItem();
            listItem.Value = i.ToString();
            listItem.Text = i.ToString(); 
            ddPages1.Items.Add(listItem);
        }  
    }
    base.Render(writer);
 }
Picrofo Software
  • 5,475
  • 3
  • 23
  • 37
mike44
  • 802
  • 5
  • 15
  • 36
  • Is the SelectedIndexChanged listener contained in the user control's code behind? Also, are you databinding the lists? – Clay Garrett Nov 01 '12 at 04:44
  • Are you using data binding to populate the drop down list? If so, can we see the code for this? – nick_w Nov 01 '12 at 04:51

3 Answers3

1

Try this:

Where you have ddPages1.Items.Add(listItem);, replace it with

if(!this.IsPostBack)
{
    ddPages1.Items.Add(listItem);
}

The problem you could be having here is that by populating the list every time, you will be losing the selection.

nick_w
  • 14,758
  • 3
  • 51
  • 71
0

Please provide more information? How do you bind to the SelectedIndexChanged event? Are you binding it programmatically? or using the declarative form?

Have you enabled ViewState?

BuddhiP
  • 6,231
  • 5
  • 36
  • 56
0

You have the set the Autopostback = true on your dropdownlist, but probably you dint put the Autopostback = true on your usercontrol

Shiridish
  • 4,942
  • 5
  • 33
  • 64