Problems injecting server side variables using <%#
I was hav开发者_开发技巧ing problems inserting a string into the following tag :
<tr id="rowBulkOptions" style='<%# sBulkOptionsRowStyle %>'>
Don't ask why I'm using tables :)
sBulkOptionsRowStyle is a Public string in the aspx.vb file.
Seemingly the only way I can get this to render is to put
Page.DataBind()
in the Page_Load, Page_PreRender etc.. However this causes me problems because Page.DataBind() binds all controls on the page.
I could use <%= BUT another part of the code inserts controls into the page and apparently you can't use <%= and insert controls.
Is there a way I can just say 'look, put sBulkOptionsRowStyle into the page please!' ?
Thanks.
The <%#
tag is used when binding to a repeating control, I take it this is not what you are doing?
As you are dynamically modifying the controls then as you stated you can also not use <%=
.
My suggestion would be that you add the tag runat="server"
to your tr and then assign the variable to the Style attribute of the control within the page load/init of your code behind.
e.g.
<tr id="rowBulkOptions" runat="server">
And in code behind
rowBulkOptions.Attributes["Style"] = sBulkOptionsRowStyle;
精彩评论