Changing width and height of a web control

If you want to set the width and the height of a web control, you can’t just call it like f.e. the text property and give it a certain value in pixels or percentage. This will result in an error. You need to use one of the static functions of the Unit class. You can set the size via pixels or percentage. This works like this:

protected void btnChangeSize_Click(object sender, EventArgs e) { lblResult.Width = Unit.Pixel(100); lblResult.Height = Unit.Percentage(5); lblResult.Text = "Width: " + lblResult.Width + ", Height: " + lblResult.Height; }


No comments yet. Be the first.

Leave a reply

*
To prove you're a person (not a spam script), type the security word shown in the picture. Click on the picture to hear an audio file of the word.
Click to hear an audio file of the anti-spam word