我正在使用Asp.Net
Content Placeholder
动态创建一个按钮,但无法让它看起来很精致
这是我想要创建的:
Asp.Net代码
<asp:LinkButton ID="LinkButton1" runat="server" Text="<i class='glyphicon glyphicon-plus'></i> Add more" CssClass="btn btn-default btn-xs" OnClick="Button1_Click" Style="margin-left: 435px"></asp:LinkButton>
asp.net
代码正常
C#CODE
LinkButton add_more = new LinkButton();
add_more.Text = "Add more";
add_more.Click += new System.EventHandler(Button1_Click);
add_more.Width = 75;
add_more.Height = 25;
add_more.Attributes.Add("style", "margin-left:435px");
add_more.Attributes.Add("Class", "glyphicon glyphicon-plus btn btn-default btn-xs");
看起来像
答案 0 :(得分:1)
Yuo应该在linkbutton
的openning和ending标签之间添加<i class='glyphicon glyphicon-plus'></i> Add more
<asp:LinkButton ID="LinkButton1" runat="server" Text="" CssClass="btn btn-default btn-xs" OnClick="Button1_Click" Style="margin-left: 435px">
<i class='glyphicon glyphicon-plus'></i> Add more
</asp:LinkButton>
好的,如果要将LinkButton添加到PlaceHolder,请执行以下操作。
<asp:PlaceHolder ID="placeHolder" runat="server" >
</asp:PlaceHolder>
在代码背后,
protected void Page_Load(object sender, EventArgs e)
{
System.Web.UI.WebControls.LinkButton add_more = new System.Web.UI.WebControls.LinkButton();
add_more.Text = "<i class='glyphicon glyphicon-plus'></i> Add more";
add_more.Click += new System.EventHandler(Button1_Click);
add_more.Attributes.Add("style", "margin-left:435px");
add_more.Attributes.Add("Class", "btn btn-default btn-xs");
placeHolder.Controls.Add(add_more);
}