ASP.Net DropDownList SelectedIndexChanged事件触发但什么都不做

时间:2016-09-30 10:18:59

标签: c# asp.net updatepanel dropdown selectedindexchanged

我有以下<TEST_REQUEST> <CITY_NAME>abc</CITY_NAME> <STATE_NAME>xyz</STATE_NAME> </TEST_REQUEST> 代码:

code.aspx:

    @XmlAccessorType(XmlAccessType.FIELD)
    @XmlRootElement(name = "TEST_REQUEST")
    @JsonIgnoreProperties(ignoreUnknown = true)
    public class TestRequest {

      @XmlElement(name = "CITY_NAME")
      @JsonProperty(value = "cityName")
      private String city;

      @JsonProperty(value = "stateName")
      @XmlElement(name = "STATE_NAME")
      private String state;

      public String getCity() {
        return city;
      }

      public void setCity(String city) {
        this.city = city;
      }

      public String getState() {
        return state;
      }

      public void setState(String state) {
        this.state = state;
      }
    }

code.aspx.cs:

ASP.Net

我的期望:

此代码应在<asp:UpdatePanel ID="upMain" runat="server"> <ContentTemplate> <table> <tr> <td>DropDownList One</td> <td> <asp:DropDownList ID="ddlOne" runat="server" AutoPostBack="true" OnSelectedIndexChange="ddlOne_SelectedIndexChanged" /> </td> <td>DropDownList Two</td> <td> <asp:DropDownList ID="ddlTwo" runat="server" /> </td> </tr> </table> </ContentTemplate> </asp:UpdatePanel> 所选索引更改时显示protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { ddlTwo.Visible = false; } } protected void ddlOne_SelectedIndexChanged(object sender, EventArgs e) { ddlTwo.Visible = true; }

实际发生的事情:

更改ddlTwo的索引后,ddlOne函数运行(使用debug进行测试),ddlOne也会运行,但是当我逐步完成该过程时,属性会发生变化但是功能结束的那一刻,我想看到我的结果(即可见的ddlOne_SelectedIndexChanged控件),没有结果。

如果有人能发现问题,请告诉我。 谢谢!

2 个答案:

答案 0 :(得分:2)

尝试

<Triggers>
    <asp:AsyncPostBackTrigger ControlID="ddlOne" 
    EventName="SelectedIndexChanged" />
</Triggers>

内部更新面板。

答案 1 :(得分:1)

更改此行

OnSelectedIndexChange="ddlOne_SelectedIndexChanged"

OnSelectedIndexChanged="ddlOne_SelectedIndexChanged"

它应该有用。