[英]SelectedIndexChanged in Custom UserControl not firing
I have been handed an old .Net 1.1 application with the words "make it run again". 我已经收到一个旧的.Net 1.1应用程序,上面写着“使其再次运行”。 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. 开发人员创建了一个自定义控件,其中包含一个html表行<tr>
和4个<td>
元素。
Now inside on of those, there is a <asp:Dropdownlist>
: 现在里面有一个<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: 方法edit_jahr_SelectedIndexChanged
看起来像这样:
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. 当前的问题是:OnSelectedIndexChanged事件没有触发,因此没有添加新的Usercontrol,因此在页面上运行的代码将失败。
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. 在沙盒解决方案中重建控件后,我终于找到了一种到达EventHandler的方法。
I had to register the SelectedItemChanged event in the OnLoad method: 我必须在OnLoad方法中注册SelectedItemChanged事件:
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. 如果有人可以回答并详细解释这个问题,我愿意接受它作为回答,而不是我自己的帖子。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.