Web Forms :: Formatting Layout Of Dynamically Added Controls?
Sep 27, 2010
Ihave the following code and would like to be able to control the layout of the textboxes and labels so they arent just in a long column. Right now everything works and controls are added, but they are added in 1 column which if you chose 32 from the dropdown the page becomes very long.. so would like to maybe wrap them across 3 columns so that each has at least 10 per column.
I'm adding a serires of asp:literal and asp:textbox controls to a panel in code as below (the eventual aim being to add only some of the controls depending on the user):
[code]....
How can I control how the panel is rendered, preferably without having to create a custom control?
I have a problem with the layout of my datalist. Everything works except for the layout of the datalist. It's currently display 2 columns in a table layout. From the looks of it, when it switches over to the second column my format gets messed up and I mean there are random gaps in certain areas. Is there a way to fix this?
I am creating a survey page that has a list of questions and answers that can be radiobuttonlists, checkboxlists or textboxes. These controls are added dynamically to a Repeater in its ItemDataBound event using Controls.Add.
I've managed to render the page ok but when I submit the form and iterate over the controls in the repeater to get the selectedvalues of the radiobuttons and textbox values, FindControl returns null. What do I need to do to get get the selected values? I've tried iterating over the RepeaterItems but that returned null too. I've tried different types of FindControl but it never resolves the control types.
It works if I add a declarative DataBinder in the Repeater like this
However, I want want to dynamically add the controls but in doing this i cant get the selectedvalues when submitting. This is tha main structure of my code...
I have a page that has customer information. I have a requirement to be able to add multiple points of contacts to a contact, so I want to dynamically be able to add a block of label/text boxes with a save/delete button attached like so for each PoC:
How best to do this? I could put a div on the page with a runat="server" and add controls I guess? Not really sure how I lay them out that way correctly though.
I have a C# web application that dynamically adds user controls to the default page for whatever "mode" the application is in. The problem is that it is not persisting these across postbacks. How do I persist these across postbacks and keep the content of the controls that are in the user control?
For instance, say I have a user control that creates a new tour record. The user clicks on the Tour item from the menu on the default page, it dynamically loads the tours user control. The user then fills out the form in the tours user control and clicks save. This is where the problem happens. When the postback occurs, the web application has no idea that the new tours user control was ever loaded. So, no save takes place because the Save button's click event never even gets fired.
I am working on a page where user controls are dynamically added to the page and refreshed with a timer in an updatepanel.
Since I already coded dynamic user control loading into the page, I would also like to implement *some* form of dynamic layout method for those controls. I was thinking coordinate values.
I have used Top and Left properties on panels before to achieve this functionality in my windows forms applications but since this is a web application things are different.
I realize I can do the whole "absolute positioning layout model" override in Visual Studio but as far as I know this only benefits me at design time. Is there a way to programatically trigger that behavior?
I looked at the silverlight Canvas and how you can pass offset values in with your controls. Something like that would be great, but this isn't Silverlight, lol. I also considered a web method to return globs of html tags to fill the area between these controls.
This is a page that would be reused over and over from client to client so this is why I would like to get this dynamic layout working. It would save me much effort later on.
How to maintain view state for the dynamically added html controls to a table using javascript(Below is the javascript which I am using to add HTML Controls Dynamically"). Because during the postbacks if I found any error while validating the data present in the dynamically added html controls, the controls are loosing their state and again I need to start adding rows and add data.
I have ONE <asp:Button ID="btnAddUC" runat="server" ......./> and ONE <asp:Table ID="tblUC" runat="server"...> on my page. User clicks on btnAddUC, user control is added to the page [user can add 'n' user controls to the page]. here I have no problem, adding user controls to the page on user clicks.
My user control has ONE <asp:DropDownList ID="ddlItems" runat="server" ......./> and ONE <asp:CheckBoxList ID="chkItems" runat="server"..../>. I am exposing "ddlItems" by public method, "chkItems" is not exposed. "chkItems" is binded on SelectedIndexChanged event of "ddlItems".
Execution scenario:
User adds user control to the page, select item from the "ddlItems" ( Note: "ddlItems" is exposed by public property ) , "chkItems" is populated ( using ddlItems.SelectedItem.Value ) . User checks some checkboxes in "chkItems" and then decide to add one more user control. When the second user control is added to the page, checkboxes in the first usercontrol lose their state and apeears unchecked (NOTE: user checked some checkboxes and then added another user control).
I want to put checked beckboxes index in session ( Before another control is added, which event I should use, because at LOAD event there is nothing).
I was able to restict SelectedIndexChanged event to only that user control whcih generated it (checking _EVENTTARGET)
I'm dynamically adding a DropDownList to the GridView in edit mode and I have set the TextBox Visibility to False. In edit mode I can see the DropDownList and I'm able to select an Item from the DropDownList but not able to access the SelectedValue in RowUpdating Event. How to get the selectedvalue of this DropDownList?
Protected Sub GridView1_RowDataBound(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewRowEventArgs) Handles GridView1.RowDataBound If e.Row.RowType = DataControlRowType.DataRow And (e.Row.RowState And DataControlRowState.Edit) > 0 Then Dim ddl as DropDownList FillStateList(ddl) e.Row.Cells(4).Controls.Add(ddl)
ddl is the DropDownList that is added dynamically. And the default Textbox that is in the Edit mode is set to invisible. So there are actually two controls in the same cell in edit mode(TextBox is invisible).
If I use the above statement I'm getting NullException.This is Probably because its a BoundField. Is there a way I can access the DropDownList 'ddl' SelectedValue?
I am adding linkbutton dynamically (actually above snippet tells what I am actually doing, in reality TableRow and TableCell are added dynamiccally). My problem is, I am not setting height of linkbuttuon which will added dynamically. I have no idea what text I have to add to linkbutton.
What I want, after all the link buttons are added, iterate through each added lin button, get the height of each linkbutton, store the max height, then re-iterate throgh the link buttons and set the height of each link button to max height.
I am having datagridview control with dynamically added BoundField columns.I want to have tetxboxes in each cell of the gridview so taht user will enter data in gridview textboxes and at last on button click it will be saved in database.
I have a page with a table and two button with the names (Submit and Add Rows) When I click on Add Row a new row will be added to a page(This is achieved using javascript), when I click on submit button I will be doing server side validation. If I found any error the error will be displayed on the page. During this process the controls which were added by me were loosing its state. As a result I need to add the rows once again and need to fill the data and click on submit button. Can any one let me know how to avoid this and see that the controls donot loose their states. So that there is no need for me to create rows once again if any validation fails on the server side.
Can any one let me know "How to load the dynamcially added HTML Controls(Controls added using javascript) during the postbacks without loosing their values?
the problem is actually in the subject. I have custom control that uses treeview. The control is added dynamically. Nodes for this treeview are populated on demand. Treeview nodes can be checked. I recreate this control on page load event, but still CheckedNodes is empty if checked nodes were added dynamically (added on demand).
Dim objDatabase As New database objDatabase.OpenSQLConnection() Dim objAdapter As SqlDataAdapter Dim objDataset As New DataSet Dim objAdapter1 As SqlDataAdapter Dim objDataset1 As New DataSet Dim objAdapter2 As SqlDataAdapter Dim objDataset2 As New DataSet
i am using above code to generate dynamicaly textbox into grid view. I have 3 fix coloumns from database which i fetch at start of code.
Then i assigned it to datatable. in datatable according to Listbox item count i added more coloumn as per listbox items count.
then that datatable i i gave as datasourse to gridview. Now i inserted dynamicaly textbox to gridview in respective coloumn.
But after refreshing page all textboxes disappears....
I have to dynamically create controls and add them to a table. In a button click I need to find the value entered for that control. The control ids are also dynamic. Below is the code I tried.
[code]....
the problem is that i m getting the rowcount=0 of the table tblUdf inside which i added the table rows and controls inside the table cells.
how to get the control values of the dynamically added controls.
I am just trying to add some dynamic controls to the SimpleQueryControl (which of course is a kind of Web Control and inherits all the methods accordingly). I dont know how to get the values of Child controls which I have added dynamically.
The controls show up fine on the page, but they don't show up when I view source, nor can I access them from the code behind.If I add the controls in the on_init method, they work. But I have some business rules driving changes to the list of controls itself that require I fire the add method elsewhere. Has anyone seen this before? I'm away from work so I can't copy the exact code.
I have two terrible ideas for how to get it working. One involves some jQuery and a set of hidden controls holding a big array of integers; the other is run the method on_init AND on my other events so the controls at least show up. Both smell like ugly hacks.
I am having trouble getting the input values of dynamically created controls in a ListView.
Here is my ListView:
[code]....
The textbox is found, but there is no value. It's like I just wrote over the textboxes with new ones in the previous block. If I remove the previous block of code no textboxes are ever found.
I am trying to create a RadioButtonListWithOther class that extends the RadoButtonList but I can't get the "Other" textbox to render on the page. When I step through while debugging I can see the control in the parent control's Controls collectio but it still doesn't render.
public class RadioButtonListWithOther : RadioButtonList { private TextBox _otherReason; public RadioButtonListWithOther() { _otherReason = new TextBox(); _otherReason.TextMode = TextBoxMode.MultiLine; _otherReason.Rows = 6; _otherReason.Width = Unit.Pixel(300); _otherReason.Visible = true; } protected override void CreateChildControls() { this.Controls.Add(_otherReason); this.EnsureChildControls(); base.CreateChildControls(); } protected override void OnSelectedIndexChanged(EventArgs e) { _otherReason.Enabled = false; if (OtherSelected()) { _otherReason.Enabled = true; } base.OnSelectedIndexChanged(e); } public override string Text { get { if (OtherSelected()) { return _otherReason.Text; } return base.Text; } set { base.Text = value; } } public override bool Visible { get { return base.Visible; } set { //Push visibility changes down to the children controls foreach (Control control in this.Controls) { control.Visible = value; } base.Visible = value; } } private bool OtherSelected() { if (this.SelectedItem.Text == "Other") { return true; } return false; } }
Here is my code to add an instance of this control to the WebForm: