2017-07-10 181 views
0

我正試圖生成對texbox OnTextChange事件的動態控件。我把斷點texbox OnTextChange事件,但它沒有進入它。 我正在使用ajax工具包自動完成擴展器將用戶名從數據庫中獲取到文本框中。當用戶在文本框中輸入的全名時,此事件將會觸發,但它不起作用。 任何解決方案動態生成控件不生成在asp.net中的文本框OnTextChanged事件c#

<asp:TextBox ID="TextBox1" runat="server" OnTextChanged="TextBox1_TextChanged" ></asp:TextBox> 
<ajaxToolkit:AutoCompleteExtender ID="AutoCompleteExtender1" runat="server" 
    ServiceMethod="GetUsers" ServicePath="WebService1.asmx" 
MinimumPrefixLength="1" 
CompletionInterval="100" EnableCaching="false" CompletionSetCount="10" 
TargetControlID="TextBox1" FirstRowSelected="false" ></ajaxToolkit:AutoCompleteExtender> 
<asp:Label ID="webpageNames" runat="server"></asp:Label> 


<asp:Button id="new" runat="server" OnClick="new_Click"> 
</asp:Button> 
<asp:Panel ID="lblPanel" runat="server"></asp:Panel> 
<asp:Panel ID="cbPanel" runat="server"></asp:Panel> 

public static List<string> getWebPagesName() 
     { 
      List<string> li = new List<string>(); 
      li.Add("AssignRoles"); 
      li.Add("Roles"); 

      return li; 
     } 

     int o = getWebPagesName().Count; 
    public void showControls() 
     { 
      List<string> lblli = getWebPagesName(); 
      for (int i = 0; i < o; i++) 
      { 
       CheckBox cb = new CheckBox(); 
       Label lbl = new Label(); 

       cb.Text = "Allow"; 

       lbl.Text = lblli[i].ToString(); 
       lblPanel.Controls.Add(lbl); 
       cbPanel.Controls.Add(cb); 
      } 
     } 

     protected void TextBox1_TextChanged(object sender, EventArgs e) 
     { 
      showControls(); 
     } 

回答

0

嘗試添加的AutoPostBack = 「true」 設置文本框定義:

<asp:TextBox ID="TextBox1" runat="server" OnTextChanged="TextBox1_TextChanged" AutoPostback="true"></asp:TextBox>