0

I have checked every question in stackoverflow. :( But anything seems not working.. i have placed a breakpoint in the event and not firing.

I hope you get the solution Thanks

               <asp:ScriptManager ID="ScriptManager1" runat="server" />


                <asp:DropDownList AutoPostBack="true" 
                   runat="server" ID="sel_area"  class="select"
                   OnSelectedIndexChanged="sel_area_SelectedIndexChanged" EnableViewState="true">
                </asp:DropDownList>

                 <asp:UpdatePanel ID="UpdatePanel2" runat="server">
                  <Triggers>
                   <asp:AsyncPostbackTrigger ControlID="sel_area" EventName="SelectedIndexChanged" />
                  </Triggers>
                  <ContentTemplate>
                   <asp:Label ID="Label1" runat="server" Text="Label"></asp:Label>   
                  </ContentTemplate>
                  </asp:UpdatePanel>

here the c# code:

 protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
         {
               destino = destinorfc();
               tb_areas = mostrarAreas(destino);

               for (int i = 0; i < tb_areas.Rows.Count; i++)
               {

                   ListItem lst = new ListItem(Convert.ToString(tb_areas.Rows[i]["PEPCECO"]), Convert.ToString(tb_areas.Rows[i]["PEPCECO"]));
                   sel_area.Items.Insert(sel_area.Items.Count, lst);

               } 

           }

    }

 public void sel_area_SelectedIndexChanged(object sender, EventArgs e)       
     {
         Response.Write("llegué");
         string ArtistId = sel_area.SelectedValue;
         Response.Write("<script language=javascript>alert('" + ArtistId +"');</script>");
         Label1.Text = ArtistId;
         Console.WriteLine("llegueee");
          //LoadComboAlbum(ArtistId);
      } 
funkeeiads
  • 327
  • 2
  • 6
  • 20

2 Answers2

0

It Sound you are not registering event handler to you combobox

add below code into designer or Page_Load event

this.sel_area.SelectedIndexChanged += 
        new System.EventHandler(sel_area_SelectedIndexChanged);

you can also do this by follow these steps

1: selecting your combobox/dropdown

2: go to properties

3: go to event tab

4: on Selectedindexchanged Event add you handler

enter image description here

Khurram Ali
  • 1,659
  • 4
  • 20
  • 37
0

Like others have already said, it sounds like your DropDownList SelectedIndexChanged event is not subscribed to your event handler. While I can see you've done it in your code, you may be losing the event subscription somewhere. To increase your understanding of the order of events the page fires, take a look at this other SO question and answer.

https://stackoverflow.com/a/11235074/2305468

Also note that if you ever take your "sel_area" object and replace it with a new DropDownList object in the C# code, you will lose all of your subscribed events from the previous DropDownList instance, so be sure that you do not completely replace it anywhere.

Community
  • 1
  • 1
Cheddar
  • 28
  • 5