I am trying to create a dynamic Panel that contains a Table and a number of rows where one or more row will have a TextBox with a slider extender bound to it. My .aspx file has the following place holder:
<asp:PlaceHolderID="pagePanels"runat="server"></asp:PlaceHolder>
In my code behind (.aspx.cs) I have dummied up the following hardcoded method that is called in the Page_Load method to demonstrate the feasiblity:
private void CreateDynamicPanel() { Panel panel; Table table; TableRow tableRow; TableCell tableCell; TextBox textBox1, textBox2; panel = new Panel(); panel.ID = "panel1"; panel.ScrollBars = ScrollBars.Vertical; panel.Height = 600; table = new Table(); table.ID = "table1"; panel.Controls.Add(table); tableRow = new TableRow(); tableRow.ID = "tablerow1"; tableCell = new TableCell(); tableCell.ID = "tablecell1"; textBox1 = new TextBox(); textBox1.ID = "textbox1"; textBox1.Text = "50"; textBox2 = new TextBox(); textBox2.ID = "textbox2"; AjaxControlToolkit.SliderExtender slider; slider = new AjaxControlToolkit.SliderExtender(); slider.ID = "slider1"; slider.Minimum = (int) 0; slider.Maximum = (int) 100; slider.Length = 100; slider.BoundControlID = textBox1.ID; slider.TargetControlID = textBox2.ID; tableCell.Controls.Add(textBox1); tableCell.Controls.Add(textBox2); tableCell.Controls.Add(slider); // Comment out and second text box follows first in-line within row. tableRow.Cells.Add(tableCell); panel.Controls.Add(tableRow); pagePanels.Controls.Add(panel); }
Unfortunately, I cannot determine how to get the slider to "follow in-line" with the text box it is bound to. The slider ends up below the text box, which results in the table row being twice the height as I want it to be:
Update: sorry, guess I didn't figure out how to get the image in here, so here is a "stick" drawing:
+-----------------------------+
| textBox1 | <- textBox1 in tableRow
+-----------------------------+
+-----------------------------+
| |||| | <- slider is undern the text box
+-----------------------------+
If I comment out the line of code that adds the slider to the 'tableCell' controls, I see that the textbox that the slider 'TargetControlID' is set to is indeed in-line where I want the slider extender to be positioned:
Update: stick drawing:
+-----------------------------+ +----------------------------+
| textBox1 | | textBox2 | <- textBox2 follows textBox1 inline within tableRow
+-----------------------------+ +----------------------------+
Is there something that can be done to get the slider to follow the text box inline within the row?
Additionally, I couldn't find any examples of dynamically creating an AJAX SliderExtender (or possibly a NumericUpDownExtender, etc.) and adding it to a dynamically created Panel with a Table and TableRows/TableCells. I have gotten other weird exceptions in my more elaborate code (the above code snippit is stripped down) and I am concerned about that. So my last question is whether dynamically adding AJAX controls such as SliderExtender to a dynamically created Table in a Panel is generally not done/possible or are there any other issues I need to be aware of?
Any help will be greatly appreciated!
Blaine