来自代码的CSS调用无效

时间:2010-03-08 06:26:53

标签: c# .net asp.net css code-behind

我在css文件中有以下条目。

a.intervalLinks { font-size:11px; font-weight:normal; color:#003399; text-decoration:underline; margin:0px 16px  0px  0px; }  
a.intervalLinks:link { text-decoration:underline; }  
a.intervalLinks:hover { text-decoration:none; }  
a.intervalLinks:visited { text-decoration:underline; }  
a.selectedIntervalLink { font-size:12px; font-weight:bold; color:#003399; text-decoration:none; margin:0px 16px 0px 0px; }  
a.intervalLinks:active { text-decoration:underline; font-size:large ;  }

编辑试用:

a.big-link:link{}
a.big-link:visited {}
a.big-link:hover{}
a.big-link:active{font-size:1em;}

每当我点击网页中嵌入的某些链接(未显示)时,我就可以看到链接中的更改

a.intervalLinks:active { text-decoration:underline; font-size:large ;

(链接的字体会变大)

但点击页面后刷新..更改将消失

我希望在该链接中保持永远的变化......即使有页面刷新

我明白了..这只能通过asp.net

背后的代码来实现

以下代码应该可以工作:但遗憾的是它没有...可以有人帮忙吗?

protected override void OnInit(EventArgs e)
        {
            rptDeptList.ItemDataBound += new RepeaterItemEventHandler(rptDeptList_ItemDataBound);

        }

        void rptDeptList_ItemDataBound(object sender, RepeaterItemEventArgs e)
        {
            if (e.Item.DataItem == null)
                return;
            LinkButton btn = (LinkButton)e.Item.FindControl("LinkButton1");
            btn.Attributes.Add("class", "intervalLinks");  


        }

编辑试用:

   void rptDeptList_ItemDataBound(object sender, RepeaterItemEventArgs e)
            {
                if (e.Item.DataItem == null)
                    return;
                LinkButton btn = (LinkButton)e.Item.FindControl("LinkButton1");
                btn.Attributes.Add("class", "intervalLinks");  
                MyLinkButton.CssClass +=" big-link";

            }

链接的当前html代码如下所示:

<ItemTemplate>
<div class='dtilsDropListTxt'><div class='rightArrow' ></div>
<asp:LinkButton ID="LinkButton1" runat="server" Text=<%#DataBinder.Eval(Container.DataItem, "WORK_AREA")%>  
CssClass="intervalLinks" OnClick="LinkButton1_Click" ></asp:LinkButton>
</div>
</ItemTemplate>

有人可以帮忙吗?

3 个答案:

答案 0 :(得分:1)

在您访问过的链接的伪选择器中,键入您要查看的更改,例如

mylink:访问{text-decoration:line-through;}

答案 1 :(得分:1)

你的代码背后有几个错误。首先,MyLinkButton.CssClass += " big-link"就是一个例子。在您的代码中,您没有名为MyLinkButton的按钮。相反,您应该使用btn.CssClass += " big-link",因为btn是您正在处理的按钮。

其次,您的代码会将big-link类附加到所有链接按钮,因为您没有条件来检查哪个按钮实际需要新类。按下链接按钮时,您需要在ViewState中存储枚举或类似内容,以便在转发器的DataBound事件中,您可以确定哪个链接按钮应附加big-link

答案 2 :(得分:1)

最简单的方法是创建一个全新的css类。单击该项目时,删除当前类并添加新类。您可以非常简单地使用javascript或jquery或代码隐藏来完成此客户端。前者将为您节省往返次数。

相关问题