I have an ASP.Net UserControl that looks like this:
<%@ Control Language='C#' AutoEventWireup='true' CodeBehind='WebUserControl1.ascx.cs' Inherits='WebApplication2.WebUserControl1' %> <table> <tr> <td> <asp:Image ID='Image1' runat='server' Width='100' Height='100' ImageUrl='~/Logo.png' /> </td> </tr> <tr> <td> Test </td> </tr> </table>
Additionally I have an ASP web form:
<%@ Page Language='C#' AutoEventWireup='true' CodeBehind='Default.aspx.cs' Inherits='WebApplication2._Default' %> <%@ Register Tagprefix='uc1' Tagname='uc1' Src='.\WebUserControl1.ascx' %> <!DOCTYPE html PUBLIC '-//W3C//DTD XHTML 1.0 Transitional//EN' 'http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd'> <html xmlns='http://www.w3.org/1999/xhtml' > <head runat='server'> <title></title> </head> <body> <form id='form1' runat='server'> <span> <asp:PlaceHolder ID='PlaceHolder1' runat='server'></asp:PlaceHolder> </span> </form> </body> </html>
When I add several usercontrols at runtime using:
protected void Page_Load(object sender, EventArgs e) { for (int i = 0; i < 5; i++) { var test = LoadControl(@'~\WebUserControl1.ascx'); PlaceHolder1.Controls.Add(test); } }
They are added to the placeholder but aligned one below the other. I’d like them to be placed one next to another. Is this possible and if yes, how?
Regards
Make your table float:right, e.g:
Or maybe an even cleaner solution: put a div around the contents of your user control and set the div to float:right:
BTW: if the page is not wide enough to display all tables on one row, then they will be wrapped to a new line with this solution.