Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
CODE PROJECT For Those Who Code
  • Home
  • Articles
  • FAQ
Community
  1. Home
  2. Web Development
  3. ASP.NET
  4. Problem in handling SelectedIndexChanged event of a dynamically created drop down

Problem in handling SelectedIndexChanged event of a dynamically created drop down

Scheduled Pinned Locked Moved ASP.NET
helpquestion
2 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • R Offline
    R Offline
    ridda786
    wrote on last edited by
    #1

    I have created a web user control with a drop down for "Main Categories" in it and a place holder. In the page load, i am populating the main categories drop down.protected void Page_Load(object sender, EventArgs e) { if(!IsPostBack) populateCategoryField(); } On the selectedindexchanged event of this drop down, i have created another drop down for "Sub-Categories" dynamically and added it in the place holder.I have assigned the SelectedIndexChanged event for sub categories drop down like this, DropDownList ddlSubCategory = new DropDownList(); ddlSubCategory.AutoPostBack = true; ddlSubCategory.SelectedIndexChanged += new EventHandler(this.subCategories_SelectedIndexChanged); plhCategories.Controls.Add(ddlSubCategory); and in this method, another sub categories drop down is created. Now when i change the selection of sub category, it is supposed to create another sub-sub-category drop down but nothing happens. Plz anyone tell me y isnt it working?

    C 1 Reply Last reply
    0
    • R ridda786

      I have created a web user control with a drop down for "Main Categories" in it and a place holder. In the page load, i am populating the main categories drop down.protected void Page_Load(object sender, EventArgs e) { if(!IsPostBack) populateCategoryField(); } On the selectedindexchanged event of this drop down, i have created another drop down for "Sub-Categories" dynamically and added it in the place holder.I have assigned the SelectedIndexChanged event for sub categories drop down like this, DropDownList ddlSubCategory = new DropDownList(); ddlSubCategory.AutoPostBack = true; ddlSubCategory.SelectedIndexChanged += new EventHandler(this.subCategories_SelectedIndexChanged); plhCategories.Controls.Add(ddlSubCategory); and in this method, another sub categories drop down is created. Now when i change the selection of sub category, it is supposed to create another sub-sub-category drop down but nothing happens. Plz anyone tell me y isnt it working?

      C Offline
      C Offline
      Christian Graus
      wrote on last edited by
      #2

      Dynamically created controls need to be created BEFORE page load, in order that they are in existence when the viewstate is populated ( just before page load ). Otherwise, their state is not restored, nor will their events fire.

      Christian Graus - Microsoft MVP - C++ "I am working on a project that will convert a FORTRAN code to corresponding C++ code.I am not aware of FORTRAN syntax" ( spotted in the C++/CLI forum )

      1 Reply Last reply
      0
      Reply
      • Reply as topic
      Log in to reply
      • Oldest to Newest
      • Newest to Oldest
      • Most Votes


      • Login

      • Don't have an account? Register

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • World
      • Users
      • Groups