SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

This may not be possible but thought i would ask. Creating a Sharepoint webpart. In the ascx file i have a style tag. Is there any way that i could do the following:

    <style type="text/css">
       border: 1px solid Black;
       height:<%# webPartHeight %>;

where the value for height is set via a data binding expression (code behind property). I tried it and when i inspected the style the height had no value set. Any help appreciated either way :)

share|improve this question
up vote 1 down vote accepted

Just call DataBind() in, say, Page_Load and it will bind your properties to the page and you can use the exact syntax you have there.

protected string webPartHeight { get; set; }
protected void Page_Load(Object sender, EventArgs e)
    webPartHeight = "400px";
share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.