Programmatic Location of TextBoxes
-
I must be missing something in the big picture.... Using CodeBehind, how can I dynamically create new controls (in this case, TextBoxes) which I can relocate on the Web Form programatically? I can see how this is possible using Windows Forms (the LEFT and TOP calls are there), but not in a Web Form (I can't seem to find a way to change the location, just WIDTH and HEIGHT). The number (I also can't seem to create controls programatically, either...) and location of text boxes and potentially other controls will vary in my application, depending on the number of db rows retrieved from a user query. Any help is appreciated! Thanks! MikeRoad
-
I must be missing something in the big picture.... Using CodeBehind, how can I dynamically create new controls (in this case, TextBoxes) which I can relocate on the Web Form programatically? I can see how this is possible using Windows Forms (the LEFT and TOP calls are there), but not in a Web Form (I can't seem to find a way to change the location, just WIDTH and HEIGHT). The number (I also can't seem to create controls programatically, either...) and location of text boxes and potentially other controls will vary in my application, depending on the number of db rows retrieved from a user query. Any help is appreciated! Thanks! MikeRoad
I'm going to make a quick assumption ... you are using VS.NET, right? First off, I would imagine that you want could dynamically make the new controls whenever you needed to make them, for example, on the click event of a button. However, to position them programmatically you will have to play with their style attributes for this to display correctly in a web browser. First thing is to set the
positition
toabsolute
and then you can set thetop
andleft
style attributes to set their location on the page. If you are using VS.NET and have the Design Mode of a Web Form open and are using the Grid Layout for the page then you can check the HTML used for the form and see how elements are being positioned on the page that are already set through design mode. Hopefully this will give you some insight. If you are going to be displaying information back to the users from a DB then I would suggest using the DataGrid because of its amazing flexibility. Check out the many articles on http://4guysfromrolla.com[^] for some great resources on ASP.NET.Wally Atkins
Newport News, VA, USA -
I'm going to make a quick assumption ... you are using VS.NET, right? First off, I would imagine that you want could dynamically make the new controls whenever you needed to make them, for example, on the click event of a button. However, to position them programmatically you will have to play with their style attributes for this to display correctly in a web browser. First thing is to set the
positition
toabsolute
and then you can set thetop
andleft
style attributes to set their location on the page. If you are using VS.NET and have the Design Mode of a Web Form open and are using the Grid Layout for the page then you can check the HTML used for the form and see how elements are being positioned on the page that are already set through design mode. Hopefully this will give you some insight. If you are going to be displaying information back to the users from a DB then I would suggest using the DataGrid because of its amazing flexibility. Check out the many articles on http://4guysfromrolla.com[^] for some great resources on ASP.NET.Wally Atkins
Newport News, VA, USA