2014-08-28 66 views
1

基本上我有一個似乎無法激活的aspx頁面功能。我創建了一個應該在下拉菜單的selectedindexchange上運行的函數。爲什麼我的函數不能執行(ASP.NET)?

<asp:TableCell>Credit Card Type: <asp:DropDownList 
     id="DropDownCredit" 
     OnSelectedIndexChanged="creditType" 
     Runat="server"> 
     <asp:ListItem Text="Select" Value="Empty" />  
     <asp:ListItem Text="Visa" Value="Visa" />  
     <asp:ListItem Text="Mastercard" Value="Mastercard" /> 
     <asp:ListItem Text="Discover" Value="Discover" />   
     <asp:ListItem Text="American Express" Value="American Express" /> 
    </asp:DropDownList> 

在那裏你可以看到我添加了我的函數名稱來運行時,他們選擇的東西。現在我的功能本身非常簡單。

Protected Sub creditType() 
     If DropDownCredit.SelectedIndex.ToString.StartsWith("A") Then 
      TextBoxCardNumberAmerican.Enabled = True 
     Else 
      TextBoxCardNumberOthers.Enabled = True 

     End If 
    End Sub 

通過我已經設定在上述功能禁用inititally提到的兩個文本框的方式,因此只有一個是正確的,然後它被啓用。我會猜測字符串沒有被正確解釋。任何幫助將是偉大的謝謝你。

回答

0

你應該將AutoPostBack =「真」屬性添加到只有在服務器側的部分將會被執行

0

請設置

AutoPostBack="True" 

在下拉菜單的下拉 。就像這樣:

<asp:DropDownList id="DropDownCredit" 
OnSelectedIndexChanged="creditType" AutoPostBack="True" Runat="server"> 

該事件將觸發

1

兩件事情:你creditYpe方法的簽名錯誤應該是:

 
    Protected Sub creditType(Object o, EventArgs e) 

..和添加的AutoPostBack = 「真」財產給你的asp控制

 

    Credit Card Type: <asp:DropDownList 
     id="DropDownCredit" 
     OnSelectedIndexChanged="creditType" 
     AutoPostBack="true" 
     Runat="server"> 
     <asp:ListItem Text="Select" Value="Empty" />  
     <asp:ListItem Text="Visa" Value="Visa" />  
     <asp:ListItem Text="Mastercard" Value="Mastercard" /> 
     <asp:ListItem Text="Discover" Value="Discover" />   
     <asp:ListItem Text="American Express" Value="American Express" /> 
    </asp:DropDownList> 

相關問題