簡體   English   中英

為什么使控件可見時,selectedindexchanged事件不起作用

[英]Why does the selectedindexchanged event not work when making controls visible

我試圖讓我的下拉列表使四個控件在控件的selectedindexchanged事件上可見。

基本上,當用戶從下拉列表中選擇“服務器”時,事件將觸發,並且用戶應看到兩個附加選項。

到目前為止,嘗試了很多方法,包括text_changed事件,但什么也沒有。

這是我到目前為止所得到的

    //adds new fields to the form when the user selects server as the asset type
    protected void AddNewFields(object sender, EventArgs e)
    {
        //If the asset is a server then make the extra controls available
        if (TypeDDL.Text.Equals("Server"))
        {
            DNLabel.Visible.Equals(true);
            //DNLabel.Visible = true;
            DomainNameTB.Visible = true;
            RoleLabel.Visible = true;
            RoleDDL.Visible = true;
        }
    }


            <asp:DropDownList ID="TypeDDL" runat="server" DataSourceID="AssetTypeDS" 
                DataTextField="AssetTypeDescription" DataValueField="AssetTypeID" OnTextChanged="AddNewFields">
            </asp:DropDownList>

AutoPostback="True"添加到您的DropDownList中,以上代碼將觸發

作為說明:下拉列表不會自動回發到服務器。 更改選擇發生在客戶端。 添加以上內容后,它將重新發布該頁面。 如果您不希望每次有人更改選擇時整個頁面都閃爍,則可以使用某些客戶端Javascript或Jquery,也可以使用asp:UpdatePanel

請設置DropdownList的AutoPostBack =“ True”屬性...

在下拉列表中添加AutoPostBack =“ true”

<asp:DropDownList ID="TypeDDL" runat="server" DataSourceID="AssetTypeDS"  AutoPostBack="true"
                DataTextField="AssetTypeDescription" DataValueField="AssetTypeID" OnTextChanged="AddNewFields">
            </asp:DropDownList>

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM