DropDown SelectedIndex更改事件触发 [英] DropDown SelectedIndex Changed Event firing

查看:85
本文介绍了DropDown SelectedIndex更改事件触发的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个下拉列表,其中有一个selectedIndexchanged事件,该事件在第一次回发时触发(按一下按钮)并且它会在下一次回发时停止触发。



I have a dropdown which has a selectedIndexchanged event which fires on first postback(a button click) and it stops firing for the next postbacks.

<asp:DropDownList ID="AreaDD" Width="150px" AutoPostBack="True" runat="server" OnSelectedIndexChanged="AreaDD_SelectedIndexChanged">
                                </asp:DropDownList>







为什么按钮点击事件会被触发?





先谢谢




Why it is firing for button click event?


Thanks in Advance

推荐答案

1。每次在列表中选择新项目时,您的ASP.NET代码都会生成回发,如果您没有选择其他项目,或者您的项目列表只有一个项目并且此项目已被选中,则它不会生成任何回发。



2.如果您希望仅在您点击页面上的提交按钮时触发事件,并且在按下按钮之前更改了当前索引,你必须在selectedindexchangedevent上将属性 AutoPostBack 更改为 false
1. Your ASP.NET code will generate postback each time you select a new item in the list, and it will not generate any postback if you do not select other item (or your item list has only one item and this item was already selected).

2. If you want that the event to be fired only when you click on submit button from your page, and the current index was changed before to press on button, you have to change the property AutoPostBack to false.


。 ..在End Of Event中设置属性AreaDD.AutoPostBack = false;在.cs文件中。

on selectedindexchangedevent... at End Of Event set the property AreaDD.AutoPostBack=false; in .cs file.
protected void timezone_SelectedIndexChanged(object sender, EventArgs e)
      {


/// Add your Code for first index change /////////////



          timezone.AutoPostBack = false;

      }


这篇关于DropDown SelectedIndex更改事件触发的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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