Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I center an image provided as an ASP.NET image control?

The question is pretty straightforward. I have an <asp:Image> which lives in an <asp:Panel>. My goal is to provide a very basic "print preview" where either left, center, or right alignment is selected. The panel represents the full print area (a sheet of 8.5" x 11" paper) and the image inside is the area that will actually get printed. The full code is this:

<asp:Panel ID="Panel2" runat="server"
    BackColor="Black"
    BorderStyle="Inset" 
    Width="425px"
    Height="550px" >
    <asp:Image runat="server" Height="425px" ImageAlign="" />
</asp:Panel>

I set the ImageUrl property in the code behind, no problems there. If I want to align the image all the way to the left or right, I can just specify ImageAlign="[Left|Right]". However, I haven't been able to find a way to center the image in the panel. I've tried all the different ImageAlign values and none of them seem to do what I want. Am I SOL here? If I have to, I can alter the CSS class for the image or panel but I couldn't figure out anything successful with that approach either.

like image 303
Matt Ball Avatar asked Mar 01 '23 11:03

Matt Ball


1 Answers

what if you use panel HorizontalAlign="Center" property.......

<asp:Panel runat="server" ID="Panel2" HorizontalAlign="Center">
</asp:Panel>
like image 117
Muhammad Akhtar Avatar answered Mar 05 '23 17:03

Muhammad Akhtar