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. General Programming
  3. C#
  4. Setting 'OnClick' for dynamic button in Code behind

Setting 'OnClick' for dynamic button in Code behind

Scheduled Pinned Locked Moved C#
questionhelpdata-structures
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.
  • C Offline
    C Offline
    Chris McGlothen
    wrote on last edited by
    #1

    All, I've gotten myself stuck on this problem and I can't seem to find a solution.:confused: I have an initial data bound radio button list(rbl) in a table that has an OnSelectedIndexChanged event that fires at the push of a button. Next I have the code that adds a child rbl and a button that would fire a subsequent OnSelectedIndexChanged for the child rbl. My question is this - How do I set the OnClick event for the dynamically created button? Yes I know that this could be solved with a tree view control, but I'm forced to write this code in 1.1 which doesn't have this control. Here is the code - public void rbLocation_OnChange(object sender, System.EventArgs e) { DBAccess OBJBO = new DBAccess(); DataSet BaseNodeSet = new DataSet(); //insert code to add new table row Table tbl = new Table(); tbl = tblLoc; TableRow tr = new TableRow(); TableRow tr2 = new TableRow(); int numRows = tbl.Rows.Count; int iteration = numRows + 1; tbl.Rows.AddAt(numRows,tr); tbl.Rows.AddAt(iteration,tr2); //adding tablecell info TableCell td = new TableCell(); TableCell td2 = new TableCell(); TableCell td3 = new TableCell(); td.Width = 30; tr.Cells.Add(td); tr.Cells.Add(td2); //adding the radiobuttonlist for the children RadioButtonList rbChild = new RadioButtonList(); rbChild.Attributes["OnSelectedIndexChanged"] = "rbChild_OnChange()"; rbChild.DataTextField = "Description"; rbChild.DataValueField = "NodeID"; rbChild.ID = "rbChild" + iteration; rbChild.DataSource = OBJBO.GetBaseNodes(Convert.ToInt32(rbLocation.SelectedValue),3,1,out BaseNodeSet); rbChild.DataBind(); td2.Controls.Add(rbChild); //maintain the selected parent value & disable parent radiobuttonlist rbLocation.SelectedValue = rbLocation.SelectedValue; rbLocation.Enabled = false; btnOK.Visible = false; //add button that reverts to the parent radio list tr2.Cells.Add(td3); Button bk = new Button(); bk.ID = "btnBack"; bk.Text = "Previous Group"; bk.Attributes["OnClick"] = "btnBack_OnClick()"; bk.Visible = true; td3.Controls.Add(bk); }


    An American football fan - Go Seahawks! Lil Turtle

    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