添加InnerHtml的链接按钮

时间:2017-06-21 09:04:00

标签: javascript c# jquery html asp.net

我有一个列表项,其中显示了一个选项卡和一个链接按钮:

<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>

enter image description here

在其背后的代码中搜索发票并获得总收入。然后,这会更新列表项以在选项卡中显示货币和收入:

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>";

enter image description here

显示a href部分,但链接按钮消失。如何使用InnerHtml显示链接按钮?

3 个答案:

答案 0 :(得分:2)

LinkBut​​ton是一个服务器控件。您无法使用内部html创建服务器控件。您必须将控件作为子控件添加到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);

答案 1 :(得分:1)

innerHTML是DOM元素的属性,因此区分大小写。 将代码修改为liActivityInvoices.innerHTML = ...

答案 2 :(得分:0)

您无法将ASP.NET服务器控件添加为字符串文字。

使用 $process = Get-Process | ? {$_.name -like '*powersh*'} #(use -le or -ge) if ($process[0].StartTime -le $process[1].StartTime) { Stop-Process $process[1]} 添加动态服务器控件或使用将控件添加为function checkRights { $identity = [System.Security.Principal.WindowsIdentity]::GetCurrent() $princ = New-Object System.Security.Principal.WindowsPrincipal($identity) if(!$princ.IsInRole( ` [System.Security.Principal.WindowsBuiltInRole]::Administrator)) { $powershell = [System.Diagnostics.Process]::GetCurrentProcess() $psi = New-Object System.Diagnostics.ProcessStartInfo $powerShell.Path $installPath = $MyInvocation.MyCommand.Path $script = $installPath $prm = $script foreach($a in $args) { $prm += ' ' + $a } $psi.Arguments = $prm $psi.Verb = "runas" #if ($dir.Attributes -eq "Directory") { $process = Get-Process | ? {$_.name -like '*powersh*'} if (($process).Count -eq 1) { $psi.WorkingDirectory = "C:\delinf" [System.Diagnostics.Process]::Start($psi) | Out-Null return; } elseif (($process).Count -eq 2) { $psi.WorkingDirectory = "C:\Csharp" [System.Diagnostics.Process]::Start($psi) | Out-Null return; } } } checkRights 的子控件,或者您可以创建PlaceHolder