dropdownchanged事件没有在asp.net中的usercontrol中触发

时间:2013-09-17 13:08:57

标签: asp.net user-controls

我在usercontrol中有一个下拉列表,如下所示

   <asp:dropdownlist id="ddlLanguage" runat="server" AutoPostBack="true" EnableViewState="true" onselectedindexchanged="ddlLanguage_SelectedIndexChanged">
        </asp:dropdownlist>

我的selectedchanged事件即使被触发也不会被解雇

中的代码

if (!IsPostBack)
{
  //dt - is list of languages availbale in DB
 //value[0]-contains lang currently to be binded to dropdownlist based
 //remaining values (values [1]) to are to be populated to textbox
  LoadModuleInfo(dt,values)
}

     private void LoadModuleInfo(System.Data.DataTable dtLanguages, string[] values)
    {
        this.txbxModuleName.Text = values[1];

        this.ddlLanguage.DataSource = dtLanguages;
        this.ddlLanguage.DataTextField = "language_description";
        this.ddlLanguage.DataValueField = "language";
        this.ddlLanguage.DataBind();

        // set up selections on the screen 

        this.ddlLanguage.SelectedIndex = this.getIndex(dtLanguages, values[0]);

    }

  protected void ddlLanguage_SelectedIndexChanged(object sender, System.EventArgs e)
    {
          //get new values ( values[0] and values[1])
         LoadModuleInfo(dtLanguages, values);
     }

 protected int getIndex(DataTable dt, string recordId)
  {
    int intCt = 0;

    foreach (System.Data.DataRow dr in dt.Rows)
    {
        if (dr[0].ToString() == recordId)
        {
            break;
        }
        else
        {
            intCt++;
        }
    }

    return intCt;
}

我已经使用了上面的代码,但是USERCONTROL中提供的dropdownlist控件没有触发selectedchanged事件。

请帮忙。

1 个答案:

答案 0 :(得分:0)

如果你的页面根本没有刷新..很可能你在页面中有一个javascript错误