Shaik
Shaik

Reputation: 930

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>

Upvotes: 1

Views: 1023

Answers (1)

Marius B.
Marius B.

Reputation: 498

You can use something like this :

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

Upvotes: 2

Related Questions