[英]Add link button from InnerHtml
I have a list item where it shows a tab and a link button: 我有一个列表项,其中显示了一个选项卡和一个链接按钮:
<li runat="server" id="liActivityInvoices"><a href="#tabActivityInvoices">Invoices</a><asp:LinkButton runat="server" ID="btnLoadInvoice" OnClick="btnInvoiceActivity_Click" CssClass="btnListSmall" Width="90px"></asp:LinkButton></li>
In the code behind it searches for invoices and gets the total revenue. 在其后面的代码中搜索发票并获取总收入。 This then updates the list item to show the currency and revenue in the tab:
然后更新列表项以在选项卡中显示货币和收入:
liActivityInvoices.InnerHtml = "<a href=\"#tabActivityInvoices\">Invoices (" + Company.Current.DefaultCurrency + ": " + Convert.ToDecimal(ds.Tables[1].Rows[0]["TotalRev"]) + ")</a> <asp:LinkButton runat=\"server\" ID=\"btnLoadInvoice\" OnClick=\"btnInvoiceActivity_Click\" CssClass=\"btnListSmall\" Width=\"90px\"></asp:LinkButton>";
The a href
part is showing but the link button disappears. 显示
a href
部分,但链接按钮消失。 How can I show the link button using the InnerHtml? 如何使用InnerHtml显示链接按钮?
LinkButton is a server control. LinkButton是一个服务器控件。 You can't create server controls using inner html.
您无法使用内部html创建服务器控件。 You will have to instead add the control as a child control to liActivityInvoices.
您必须改为将该控件作为子控件添加到liActivityInvoices。
var anchor = new LiteralControl("<a href=\"#tabActivityInvoices\">Invoices (" + Company.Current.DefaultCurrency + ": " + Convert.ToDecimal(ds.Tables[1].Rows[0]["TotalRev"]) + ")</a>");
var lnkButton = new LinkButton
{
ID = "btnLoadInvoice",
CssClass = "btnListSmall",
Width = new Unit("90px")
};
lnkButton.Click += btnInvoiceActivity_Click;
liActivityInvoices.Controls.Add(anchor);
liActivityInvoices.Controls.Add(lnkButton);
innerHTML
is a DOM element's property and hence case sensitive. innerHTML
是DOM元素的属性,因此区分大小写。 Modify your code as liActivityInvoices.innerHTML = ...
将代码修改为
liActivityInvoices.innerHTML = ...
You can't add ASP.NET server controls as string literals. 您不能将ASP.NET服务器控件添加为字符串文字。
Use PlaceHolder
to add the dynamic server control or use add the control as a child control to liActivityInvoices
or you can create DivIndirizzo
使用
PlaceHolder
来添加动态服务器控件,或者使用将该控件作为子控件添加到liActivityInvoices
或者可以创建DivIndirizzo
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.