可能是一个“doh”时刻,但无法获得此代码隐藏功能。事实上,调试显示它甚至没有被调用,这可能是最终显示在网页上的指示,只能看到:
<table id="dnn_ctr422_ViewPloads_PagerTable">....
注意缺少的“风格”。任何帮助将不胜感激。
//aspx code
<table id="PagerTable" style="<%# GetPagerStyle() %>" runat="server">
<tr>
<td>
<asp:DataPager ID="PloadPager" runat="server" PagedControlID="PloadListView" OnPreRender ="PloadPager_PreRender" PageSize="20" >
//code behind
protected String GetPagerStyle( )
{
return "background-color:" + (String)Settings["TableBackgroundColor"];
}
从你展示的内容来看,目前还不清楚为什么它没有运行。您可能会针对与您的源不相同的版本运行,但我假设您已尝试完全重建。
知道您也可以在ASPX页面中设置断点。但我的预感是,如果不打电话,就不会召唤更多。你试过打破Page_Load
或Page_PreRender
吗?
另一种可能性是,在调用PagerTable
之前,你的GetPagerStyle
对象被其他代码更改。在这种情况下,如果在运行之前更改了style-attribute,则可能会产生此问题。解决方法并确定您是否确实可以设置样式是在Page_Load中执行以下操作:
// correction courtesy of Tim Schmelter ;)
PagerTable.Style.Add(HtmlTextWriterStyle.BackgroundColor,
(String)Settings["TableBackgroundColor"]);
编辑:注意,正如其他人指出的那样,以下内容也应该有效(尝试过,因为存在一些争议,请参阅其他答案):
<table id="PagerTable" style="<%= GetPagerStyle() %>">
但请注意,我删除了runat="server"
。这意味着,你不能再从代码隐藏中使用它了。我只是假设你在代码隐藏中没有用这个控件做任何其他事情,所以这是否适合你的情况我不知道。
你有没有打电话给Page.DataBind
,因为<%#...
是一个具有约束力的表达?
inline asp.net tags... sorting them all out
除此之外,你总是可以从codebehind设置这些东西:
protected void Page_Load(object sender, EventArgs e)
{
PagerTable.Style.Add("background-color", (String)Settings["TableBackgroundColor"]);
}
只需在代码中替换#with =
style="<%=GetPagerStyle()%>"
应该工作正常。
你有没有尝试过
<%= GetPagerStyle() %>