在我的项目中,当我单击按钮创建div时,我需要为div添加带有曲线的css类。所以我试过这个
ASP.NET
Protected Sub btnLog_Click(ByVal sender As Object, ByVal e As System.Web.UI.ImageClickEventArgs)
Handles btnLog.Click
DivUserDetail.Controls.Clear()
Dim createDiv As HtmlGenericControl = New HtmlGenericControl("DIV")
createDiv.ID = "createDiv"
createDiv.Style.Add(HtmlTextWriterStyle.Color, "Red")
createDiv.InnerHtml = " I'm a div, from code behind "
createDiv.Attributes("class") = "FirstDiv"
DivUserDetail.Controls.Add(createDiv)
End Sub
CSS
#DivUserDetail
{
width: 30%;
height: 100%;
position:absolute;
float: right;
right:0px;
top:0px;
border-Left: 1px solid #00e5e6;
overflow:auto;
}
.FirstDiv
{
height: 400Px;
width: 150px;
position:fixed;
top: 0px;
left: 0px;
border:1px solid #4BACBC;
-webkit-border-radius:15px;
-moz-border-radius:15px;
}
但它只显示文字。这里有什么问题?如何纠正?
am使用ASP.NET 2008
答案 0 :(得分:1)
您需要为新的HTML元素添加class
属性。
您在此处所做的是修改现有class
属性的值,该属性不存在。
替换它:
createDiv.Attributes("class") = "FirstDiv"
与
createDiv.Attributes.Add("class","FirstDiv")