2017-08-03 59 views
0

當我在UI中關注我的DropDownList時,它會打開並顯示數據。如果我嘗試按下Enter鍵從DropDownList中選擇文本,那麼它應該選擇一個文本並移動到另一個輸入控件。但是,我的情況並沒有發生。DropDownList輸入事件問題

選項卡選擇和鼠標選擇正在工作。它發生在我的頁面和項目有限的地方。

我嘗試通過刪除CSS解決方案。我也試過Google。但是,我沒有得到問題和答案的實際原因。

回答

0

這個工作對我來說,當我按下ENTER SelectedIndexChanged事件被調用

<%@ Page Title="Home Page" Language="C#" MasterPageFile="~/Site.Master" AutoEventWireup="true" CodeBehind="Default.aspx.cs" Inherits="WebApplication2._Default" %> 

<asp:Content ID="BodyContent" ContentPlaceHolderID="MainContent" runat="server"> 
    <asp:DropDownList ID="DropDownList1" runat="server" OnSelectedIndexChanged="DropDownList1_SelectedIndexChanged" AutoPostBack="true"> 
     <asp:ListItem>Primo</asp:ListItem> 
     <asp:ListItem>Secondo</asp:ListItem> 
     <asp:ListItem>Terzo</asp:ListItem> 
    </asp:DropDownList> 
    <asp:Button ID="Button1" runat="server" Text="Button" /> 
</asp:Content> 

這是必須添加AutoPostback=true這個工作

+0

感謝好友的幫助。我已經使用AutoPostback = true。它仍然不適合我。 –

0

如果你的控制回發與selectedIndexchange事件再下一個焦點元素將不會集中,因爲回發發生。

要做到這一點,你必須找到下一個元素,並專注於這一變化事件像下面

<asp:TextBox ID="txtFirstName" OnTextChanged="txtFirstName_TextChanged" placeholder="" AutoPostBack="true" CssClass="form-control" runat="server"></asp:TextBox> 


    <asp:TextBox ID="txtLastName" OnTextChanged="txtFirstName_TextChanged" placeholder="" AutoPostBack="true" CssClass="form-control" runat="server"></asp:TextBox> 

代碼背後:

protected void txtMEMBID_TextChanged(object sender, EventArgs e) 
    { 
    if(ValidCondition) 
    { 
     //go to next element 
     txtLastName.Focus(); 
    } 
    }