Question

I´ve been searching the web and Stackoverflow for this answer, I´ve tried some but with no success. My problem: I have a dropdownlist inside the footer of a Datalist. My page´s AutoEventWireup is set to true. My Dropdown´s autopostback is set to true. I bind the event on itemcreation of the datalist. The dropdown does get the postback but doesn´t call the function set at the SelectedIndexChanged event.

On create:

protected void dlCartItemsMonetary_ItemCreated(object sender, DataListItemEventArgs e)
{
    if (e.Item.ItemType == ListItemType.Footer)
    {
        DropDownList combo = (DropDownList)e.Item.FindControl("ddlDeliveryService");
        if (combo != null)
        {
            combo.SelectedIndexChanged += new EventHandler(ddlDeliveryService_SelectedIndexChanged);
        }
    }
}

The dropdown:

<asp:DropDownList ID="ddlDeliveryService" runat="server" AutoPostBack="true" OnSelectedIndexChanged="ddlDeliveryService_SelectedIndexChanged" EnableViewState="true">

It does the postback but it doesn´t enter the ddlDeliveryService_SelectedIndexChanged function.

Can anyone give me some tips on how to solve it?

Thanks in advance

Was it helpful?

Solution

Resolved!

My problem and many other's is that I was setting the DataSource and DataBinding the DataList on every postback. As soon as I added the postback validation the event begin to fire. Code below:

    if (this.Page.IsPostBack == false)
    {
        dlCartItemsMonetary.DataSource = list;
        dlCartItemsMonetary.DataBind();
    }

If you are having the same problem with events not firing check your code for the same issue!

Thanks jpartjh for your comment, it made me think about the lifecycle of the page.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top