troubleshooting Question

Add OnSelectedIndexChanged to Drop Down List

Avatar of gtrapp
gtrapp asked on
.NET Programming
6 Comments1 Solution2525 ViewsLast Modified:
I need to have a drop down list box to be triggered by a selection change and call some code in the code behind. I have added a OnSelectedIndexChanged="ddlPermissionLevel" on the control, but when the page loads up, I get this error message:

Compiler Error Message: CS0118: 'pbFamily.PersonalInfo_Edit.ddlPermissionLevel' is a 'field' but is used like a 'method'

I don't understand the error message. I know there is an Attribute onchange added, which may be conflicting. Any ideas on how to add a OnSelectedIndexChanged to the control?
In the ASPX file:
<asp:DropDownList id="ddlPermissionLevel" Enabled="<%# !PageReadOnly %>" runat="server" Width="100%" OnSelectedIndexChanged="ddlPermissionLevel"></asp:DropDownList>
In the Code Behind:
protected void Page_Load(object sender, System.EventArgs e)
    ddlPermissionLevel.Attributes.Add("onchange", "onChange=needToConfirm=true;");
protected void ddlPermissionLevel_SelectedIndexChanged(object sender, EventArgs e)
private void InitializeComponent()
   this.ddlPermissionLevel.SelectedIndexChanged += new System.EventHandler(this.ddlPermissionLevel_SelectedIndexChanged);
Join the community to see this answer!
Join our exclusive community to see this answer & millions of others.
Unlock 1 Answer and 6 Comments.
Join the Community
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 6 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros