DropDownList OnSelectedIndexChanged不会触发

时间:2016-05-10 10:10:42

标签: c# asp.net razor ascx asp.net-webpages

我有MVC4 Web应用程序,我在.cshtml页面中呈现部分视图(.ascx)。我添加了一个具有OnSelectedIndexChanged的下拉列表,它永远不会触发。请参阅下面的代码

Dashboard.ascx

<%@ Control Language="C#" AutoEventWireup="true" CodeBehind="Dashboard.ascx.cs" Inherits="iSPYCMS.Views.Dashboard" EnableViewState="true" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">  
<html xmlns="http://www.w3.org/1999/xhtml">  
<head id="Head1" runat="server">  
<title>Charts Example</title>  
</head>  
<body style="padding:50px;background-color:white">         

<form id="form1" runat="server">  

    <asp:DropDownList runat="server" ID="cmbTypeSeletion" Height="16px" Width="190px" EnableViewState="true" Enabled="true" OnSelectedIndexChanged="cmbTypeSeletion_SelectedIndexChanged">
        <asp:ListItem Enabled="true" Text="Downloads" Value="Downloads"> </asp:ListItem>
        <asp:ListItem Enabled="true" Text="Plays" Value="Plays"></asp:ListItem>
        <asp:ListItem Enabled="true" Text="Completion" Value="Completion"></asp:ListItem>
    </asp:DropDownList>
<div>  
    <script type="text/javascript" src="https://www.google.com/jsapi"> </script>  
    <asp:Literal ID="ltScripts" runat="server"></asp:Literal>  
    <div id="chart_div">  
    </div>  
</div>  
</form>  
</body>  
</html>  

Dashboard.ascx.cs

namespace iSPYCMS.Views
{
  public partial class Dashboard : ViewUserControl
  {
    protected void cmbTypeSeletion_SelectedIndexChanged(object sender, EventArgs e)
    {

    }
  }
}

Index.cshtml

@{
Layout = "~/Views/Shared/_Layout.cshtml";
}

<div>
 @Html.Partial("~/Views/Dashboard.ascx")
</div>

1 个答案:

答案 0 :(得分:0)

设置AutoPostBack =&#34; True&#34;对于下拉列表