简体   繁体   中英

On change show alert C# asp.net

I am trying to check if else condition works on the asp.net C# code behind what am not getting is on dropdown change there is a condition if selected index value is zero then alrt 0 alert but nothing shows on any of the selected index is selected not sure where am i going wrong.

CS: Code Behind

  protected void Student_type_dd_change(object sender, EventArgs e)
        {

            if (Student_type_dd.SelectedIndex == 0)
            {
                Response.Write("<script>alert('0');</script>");
            }
            else if (Student_type_dd.SelectedIndex == 1)
            {
                Response.Write("<script>alert('1');</script>");
            }
            else if (Student_type_dd.SelectedIndex == 2)
            {
                Response.Write("<script>alert('2');</script>");
            }

        }

Aspx

 <asp:DropDownList ID="Student_type_dd" runat="server" onselectedindexchanged="Student_type_dd_change" autopostback="true" >
                    <asp:ListItem Text="Select Type" Value="0" />
                      <asp:ListItem Text="All Students" Value="All Students" />
                         <asp:ListItem Text="Class Wise" Value="Class Wise" />
                         <asp:ListItem Text="Select Specific" Value="Select Specific" />
                </asp:DropDownList>

您可以使用如下所示的内容:

ScriptManager.RegisterStartupScript(this, typeof(Page), "alert", "alert('0')", true);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM