下拉所选索引更改事件无法正常工作 [英] Drop down selected index change event not working properly

查看:76
本文介绍了下拉所选索引更改事件无法正常工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你好朋友,

我有一个用户控件UC1,它已在另一个用户控件UC2中注册.
在UC1中,我有一个下拉列表,并且我也正确执行onselectedindexchanged()事件,但是当我更改下拉列表的索引时,不会触发该事件.

Hi friend,

I have one user control UC1 which is register in another user control UC2.
In UC1 i have one drop down and i right onselectedindexchanged() event for same, but it is not raised when i change index of drop down.

<asp:DropDownList ID="DropDownList1" runat="server" AutoPostBack="true" OnSelectedIndexChanged="DropDownList1_SelectedIndexChanged">
              </asp:DropDownList>





protected void DropDownList1_SelectedIndexChanged (object sender, EventArgs e) 
{
//some functionality
}



但是当我单击UC2上的按钮时会触发此事件



but this event fired when i click on button which is on UC2

plz tell me why this is happend?

推荐答案

当autopostback设置为True时,呈现页面后,在下拉菜单的onchange事件上添加一个javascript( HTML中的SELECT)触发回发,

呈现页面后查看源代码,并检查javascript是否已添加到下拉列表的onchange事件中.

如果您要在代码后面的下拉菜单的onchange事件中添加一些javascript,这也可能会阻止页面回发.
When the autopostback is set True, after the page is rendered, a javascript is added on the onchange event of the dropdown (SELECT in HTML) to trigger the postback,

View the source after the page is rendered and check whether the javascript is getting added to the onchange event of the dropdown.

If you are adding some javascript on the onchange event of the dropdown in the code-behind, that might also stop the page to postback.


我不能说太多阅读您的描述,但看起来您需要将DropDown的AutoPostBack属性设置为true.
这样,当您更改所选索引时,页面将自动进行回发.

在您的情况下,单击按钮会导致页面回发,然后,如果您更改了下拉列表的选定索引,则也会触发DropDownList1_SelectedIndexChanged事件.

如果这不是正确的解决方案,请发送您的标记和代码,以便我们进行调查.
I can''t say much reading yours description, but it looks like you need to set AutoPostBack property of DropDown to true.
This way page will make postback automatically when you change selected index.

In your case button clicking caused the page postback and then, if you changed selected index of your dropdown, DropDownList1_SelectedIndexChanged event if fired too.

If this is not a right solution, send yours markup and code so we can investigate whats happening.


设置DropDown的AutoPostBack属性将为您解决.
Setting AutoPostBack property of DropDown will do for you.


这篇关于下拉所选索引更改事件无法正常工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆