【问题标题】:Why does dropdownlist selected option does not cause postback second Time?为什么下拉列表选择的选项不会导致第二次回发?
【发布时间】:2010-01-27 12:47:29
【问题描述】:

我有两个下拉列表,选择第一个下拉列表会导致回发,第二个下拉列表会被绑定...

  • 为什么第一个下拉列表的选中值,再次选中不会导致回发?

编辑:

 <asp:DropDownList ID="DLMatName" runat="server" OnSelectedIndexChanged="DlMeasurement_SelectedIndexChanged" AutoPostBack="true">
                                               </asp:DropDownList>


protected void DlMeasurement_SelectedIndexChanged(object sender, EventArgs e)
{

    if (DLMatName.SelectedIndex != 0)
    {
        DataTable dt = _materialInController.GetMeasurementsforMaterials(Convert.ToInt64(DLMatName.SelectedValue.ToString())).Tables[0];
        if (dt.Rows.Count > 1)
        {
            MeasurementTr.Visible = true;
            this.DlMeasurement.DataSource = dt;
            this.DlMeasurement.DataValueField = dt.Columns[0].ToString();
            this.DlMeasurement.DataTextField = dt.Columns[1].ToString();
            this.DlMeasurement.DataBind();
            this.DlMeasurement.Items.Insert(0, ListItem.FromString("Select"));
            this.LblMeasuremet.Visible = false;
            ErrorMsg.InnerHtml = "";             
        }
        else if (dt.Rows.Count == 1)
        {
            this.LblMeasuremet.Visible = true;
            this.LblMeasuremet.Text = dt.Rows[0].ItemArray[1].ToString();
            MeasurementTr.Visible = false;
            ErrorMsg.InnerHtml = "";       

        }
        else
        {

        }
    }
    else
    {
        MeasurementTr.Visible = false;
        this.LblMeasuremet.Visible = false;
        ErrorMsg.InnerHtml = "Select the materialType";
    }
    ScriptManager.RegisterClientScriptBlock(DLMatName, typeof(DropDownList), "Hideimage", "HideImageButtonDivforAdd();", true);

}

第一次选择值回发,第二次选择不回发时相同...

【问题讨论】:

  • 发布您的代码会更有帮助,即您的 aspx 标记。
  • 您是否将下拉列表的 AutoPostBack 属性设置为 true?如果是这样,请在您的问题中添加一些代码。
  • 您是否尝试过注释掉“ScriptManager.RegisterClientScriptBlock”调用?
  • 第一次回发后,你能看到页面源上是否还有连接到 DropList 的 JScript 事件吗?
  • 我已经删除了 javascript 事件……它开始工作了……谢谢……

标签: asp.net drop-down-menu postback


【解决方案1】:

您是否在页面的每个回发时重新绑定第二个下拉列表,即在您的 Page_Load 事件中您是否有任何代码,例如:

protected void Page_Load(object sender, EventArgs e)
{
      if (DropDown1.SelectedIndex > 0)
      {
          // Rebind the second dropdown. 
      }
}

如果是这样,那么您错过了检查页面是否正在回发到自身 (Page.IsPostBack) 的检查,这会导致您的问题。

【讨论】:

    猜你喜欢
    • 2017-12-16
    • 1970-01-01
    • 2017-12-17
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多