Tag Archives: FontUnit

Setting Width or Font size from code behind / dynamically

When we are declaring any Label/button from code behind then we can also set the font size/width for the same

For Width its considered in Unit & Font Size is considered in FontUnit

For Label

We can’t use directly –

lblParameterName.Font.Size = “10px”;                                                                                                                                                              you will get error – Cannot implicitly convert type ‘string’ to ‘System.Web.UI.WebControls.FontUnit’

We can use the following way –  lblParameterName.Font.Size = new FontUnit(10); Here we are setting the fontsize to 10;

For Button –

We can’t use directly –

btnParameterName.width = “10px”;     you will get error – Cannot implicitly convert type ‘string’ to ‘System.Web.UI.WebControls.Unit’

We can use the following way –  btnParameterName.width = Unit.Pixel(10); Here we are setting the widthto 10px;

Detail Ref – MSDN Unit

Advertisements