Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/305.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 如何设置代码中文本框的超链接。-使用其他HTML标记_C#_Asp.net_Html_Vb.net - Fatal编程技术网

C# 如何设置代码中文本框的超链接。-使用其他HTML标记

C# 如何设置代码中文本框的超链接。-使用其他HTML标记,c#,asp.net,html,vb.net,C#,Asp.net,Html,Vb.net,我想在文本框中显示的代码 <a href="http://www.erate.co.za/CompanyProfile.aspx?ID=112"> <img src="http://www.erate.co.za/CompanyAdd.bmp" alt="Go rate us on www.eRate.co.za" border="0" style="width: 136px; height: 88px" /></a> 现在我想将txtCode.tex

我想在文本框中显示的代码

<a href="http://www.erate.co.za/CompanyProfile.aspx?ID=112">
<img   src="http://www.erate.co.za/CompanyAdd.bmp" alt="Go rate us on www.eRate.co.za" 
border="0" style="width: 136px; height: 88px" /></a>
现在我想将txtCode.text设置为该值,但它不起作用

txtCode.Text = "<a href="http://www.erate.co.za/CompanyProfile.aspx?ID=" +  
reader.Item("ID").ToString + ">
<img  src="http://www.erate.co.za/CompanyAdd.bmp" alt="Go rate us on www.eRate.co.za"
border="0" style="width: 136px; height: 88px" /></a>"
txtCode.Text=“”
我该怎么做

艾蒂安

txtCode.Text=@;
txtCode.Text = @"<a href=""http://www.erate.co.za/CompanyProfile.aspx?ID=" +  
reader.Item("Desc_Work").ToString() + @">
<img  src=""http://www.erate.co.za/CompanyAdd.bmp"" alt=""Go rate us on www.eRate.co.za""
border=""0"" style=""width: 136px; height: 88px"" /></a>";

试试看,看是否有效。

我想你的问题是关于引号的,在VB.NET中试试这个:

txtCode.Text = "<a href='http://www.erate.co.za/CompanyProfile.aspx?ID=" 
& reader.Item("ID").ToString 
& "><img  src='http://www.erate.co.za/CompanyAdd.bmp' alt='Go rate us on www.eRate.co.za' border='0' style='width: 136px; height: 88px' /></a>"
txtCode.Text=“”

使用:\“转义所有引号,或使用单引号而不是双引号。

您可以将图像和链接组合到asp:Imagebutton中,而不是普通的旧HTML锚定标记,并从onClick处理程序上的代码中动态设置链接地址,如下所示:

.aspx:

<asp:ImageButton ImageUrl="http://www.erate.co.za/CompanyAdd.bmp" onClick="imgBtnClick" id="ibRateUs" runat="server" />
VB中的相同后端代码:

public sub imgBtnClick(sender as Object, e as System.EventArgs)
    Dim url as String = "http://www.erate.co.za/CompanyProfile.aspx?ID=" + reader.Item("Desc_Work").ToString
    Response.Redirect(url, false)
end sub
如果ImageButton超出单击处理程序的范围,则可能需要将ID作为命令参数传递给ImageButton

这种设置可能比替换文本框中的文本更具可读性和灵活性


希望这对您有所帮助。

在VB中,引号字符用另一个引号转义:

txtCode.Text = "<a href=""http://www.erate.co.za/CompanyProfile.aspx?ID=" & reader.Item("ID").ToString() & ">"
txtCode.Text &= "<img src=""http://www.erate.co.za/CompanyAdd.bmp"" alt=""Go rate us on www.eRate.co.za"" border=""0"" style=""width: 136px; height: 88px"" /></a>"
在C#中,它必须是:

reader.Item["ID"].ToString()

它抱怨第一个@sign-Message=字符无效。这是因为您使用的是VB,我相信@BFree假设它是C#。明白了!当我知道问题是因为引号的缘故时,我删除了我的评论。谢谢!我只需在我的reader.Item(“ID”).ToString()末尾添加另一个“符号”。
txtCode.Text = "<a href=""http://www.erate.co.za/CompanyProfile.aspx?ID=" & reader.Item("ID").ToString() & ">"
txtCode.Text &= "<img src=""http://www.erate.co.za/CompanyAdd.bmp"" alt=""Go rate us on www.eRate.co.za"" border=""0"" style=""width: 136px; height: 88px"" /></a>"
reader.Item("ID").ToString
reader.Item["ID"].ToString()