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
  1. Home
  2. Web Development
  3. ASP.NET
  4. Problem in Creating Dyamic Web Controls

Problem in Creating Dyamic Web Controls

Scheduled Pinned Locked Moved ASP.NET
designhelptutorial
1 Posts 1 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.
  • N Offline
    N Offline
    naresh_pandey13
    wrote on last edited by
    #1

    Hi friends, The code is given beolow....I want to add number of controls according to the value selected in dropdownlist. But as i m inccrementing the value of ViewState variable in SelectedIndexChanged event depening on the selection.if i print that value then it is showing the correct value...but it is taking this value in the 2nd postback....not in the (current)postback caused by SelectedIndexChanged event ..... Plz tell me wat should i have to do to correct this problem..... Also if any idea about how to handle events on dynamic controls ... Thanks a lot in advance friends.:omg: public class WebForm3 : System.Web.UI.Page { protected System.Web.UI.WebControls.PlaceHolder PlaceHolder1; protected System.Web.UI.WebControls.DropDownList dd; private void Page_Load(object sender, System.EventArgs e) { if(!Page.IsPostBack) { this.NumberOfControls = 0; } else { createControls(); } } protected int NumberOfControls { get{return (int)ViewState["NumControls"];} set{ViewState["NumControls"] = value;} } public void createControls() { int cnt = this.NumberOfControls ; for (int i=0; i"));); } } //dd is a DropDownList containing values 1,2 ,3,4,5,6..... //This event is incrementing the ViewState variable to some value so as to add some more controls private void dd_SelectedIndexChanged(object sender, System.EventArgs e) { this.NumberOfControls = this.NumberOfControls + Convert.ToInt32(dd.SelectedItem.Text); //here if i print the numberofcontrols then it gives correct value.. // but on postback it is taking effect(means Taking this incremented value) after one more PostBack //TELL ME WAT SHOULD I HAVE TO DO TO CREATE DYNAMIC CONTROLS ON SELECTION FROM THIS DROPDOWNLIST } } naresh

    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