I stumbled upon another issue. I am sure there is a good reason they decided to not allow this, but I found it quite frustrating to learn it the hard way. Server Control tags, like for a button, or TextBox or any other server control, can not contain .net code <% … %>. For example:
<asp:Button ID=”btnRefreshLayout” runat=”server” Text=”Refresh Layout” OnClientClick=”AdjustFrameDim(<%= _layout%>);” OnClick=”btnRefreshLayout_Click” />
The result is…
<input type=”submit” name=”btnRefreshLayout” value=”Refresh Layout” onclick=”AdjustFrameDim(<%= _layout%>);” id=”BI_TabControl1_ucLayout_btnRefreshLayout” />
It doesn’t seem to matter where in the server control code you put the <% … %>, it doesn’t work.
BUT, I have good news… If you need to dynamically add something to the properties of the server control, you could instead use the AddAttribute method of the server control and get the needed results that way.
btnRefreshLayout.Attributes.Add(“OnClick”, “AdjustFrameDim(“ + _layout + “);”);
Happy Coding.

4 comments
Comments feed for this article
January 12, 2007 at 11:08 pm
Christian Maslen
There is a markup based way to acheive this using a custom expression builder. The following blog post details how it’s done.
http://weblogs.asp.net/infinitiesloop/archive/2006/08/09/The-CodeExpressionBuilder.aspx
December 21, 2007 at 1:09 pm
Melina
very interesting. i’m adding in RSS Reader
March 16, 2008 at 1:24 pm
Some.Net(Guy)
try using single quotes, ie:
onclick=’AdjustFrameDim();’
October 14, 2009 at 3:23 am
sq33G
http://weblogs.asp.net/infinitiesloop/archive/2006/08/09/The-CodeExpressionBuilder.aspx
has the answer