简体   繁体   中英

SelectedIndexChanged in Custom UserControl not firing

I have been handed an old .Net 1.1 application with the words "make it run again". I am now in the process of migrating this old beast.

The developer has created a custom control, which contains of a html table row <tr> and 4 <td> elements.

Now inside on of those, there is a <asp:Dropdownlist> :

 <asp:DropDownList id="edit_jahr" runat="server" 
                   AutoPostBack="True" 
                   OnSelectedIndexChanged="edit_jahr_SelectedIndexChanged">
 </asp:DropDownList>

The method edit_jahr_SelectedIndexChanged looks like this:

protected void edit_jahr_SelectedIndexChanged(object sender, System.EventArgs e)
{
    JahrChangedEventArgs args = new JahrChangedEventArgs((int)ViewState["jahr"],Convert.ToInt32(edit_jahr.SelectedValue));
    OnJahrChange(args);
    this.Jahr=args.NeuesJahr;
}

The problem at hand is: the OnSelectedIndexChanged event is not firing, therefor no new Usercontrol is added and therefor the code running on the page will fail.

Please point me in the right direction. Why is this not working and how can I solve this.

After rebuilding the control in a sandbox solution, I finally found a way to reach the EventHandler.

I had to register the SelectedItemChanged event in the OnLoad method:

protected override void OnLoad(EventArgs e)
{
    base.OnLoad(e);
    edit_jahr.SelectedIndexChanged += new EventHandler(edit_jahr_SelectedIndexChanged);
}

I do not why, honestly. If somebody can answer & explain this in detail, I'm willing to accept this as an answer, instead of my own post.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM