将HyperLink Control更改为Href不起作用

时间:2017-01-12 15:55:57

标签: javascript asp.net vb.net

我有一个Hyper Link控件添加到面板,它工作。我需要将其替换为href,以便在页面中保持一致的其他控件。但是,当我在VS 2015中调试它时,我的脚本出错。错误消息是:“第333行的JavaScript严重错误,http://localhost:603/Order/buyerProfile.aspx?Id=42940中的第255列\ n \ nSCRIPT1002:语法错误”

有人会告诉我如何解决它。提前谢谢。

我的HperLink控件代码有效:

Dim hypOrder As New HyperLink
Dim onClick As String = "openWin('OrderForm/pop.aspx"
                onClick &= "','',500,270);return false;"
                hypOrder.Text = "Test page"
                hypOrder.Attributes.Add("onclick", onClick)
pnlLink.Controls.Add(hypOrder )

我的代码需要更改为href:

dim href1 as string
Dim href1 As String = "<a target='_blank'  class='body'" & "href='#'"
href1 = href1 & " onclick='openWin('OrderForm/pop.aspx','',500,270);return false;"
href1 = href1 & "'>" & Test page & "</a>"
 Dim ltLink As New Literal
 ltLink.Text = href1
 pnlSecurityFlagsLink.Controls.Add(ltLink)

我调试href文本是:

  <a target='_blank'  class='body' href='#' onclick='openWin('OrderForm/pop.aspx','',500,270);return false;'>Test page </a>

1 个答案:

答案 0 :(得分:0)

onclick=内的行上有多个单引号。您必须使用双引号才能使其正常工作。

href1 = href1 & " onclick=""openWin('OrderForm/pop.aspx','',500,270);return false;"">Link</a>"

要转义",请将其设为双""