Click here to Skip to main content
15,896,557 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
i try this dropdown list with onclick

What I have tried:

ASP.NET
<asp:DropDownList ID="DropDownList1" runat="server" 
    onselectedindexchanged="DropDownList1_SelectedIndexChanged"
     onclick="Loadchart();">





but this shows error
Validation (ASP.Net): Attribute 'onclick' is not a valid attribute of element 'DropDownList'.

where as i call this dropdown on page load
C#
DropDownList1.DataSource = getyear();
               DropDownList1.DataTextField = "year";
               DropDownList1.DataValueField = "year_id";
               DropDownList1.DataBind();


When i build this shows error any solution
Posted
Updated 9-May-16 0:35am
v2

1 solution

Remove that event from mark up and add bind the event from code behind during page
load.
however, onchange event should helpful in case of Dropdownlist events. anyhow its upto your requirement.

ASP.NET
<asp:dropdownlist id="DropDownList1" runat="server" >
         OnSelectedIndexChanged="DropDownList1_SelectedIndexChanged"></asp:dropdownlist>


CS

C#
protected void Page_Load(object sender, EventArgs e)
      {
          if (!IsPostBack)
          {
              DropDownList1.Attributes.Add("onclick", "Loadchart();");
          }
      }
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900