Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/html/87.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# 从codebehind(或前端)设置mailto_C#_Html_Asp.net - Fatal编程技术网

C# 从codebehind(或前端)设置mailto

C# 从codebehind(或前端)设置mailto,c#,html,asp.net,C#,Html,Asp.net,我必须修改以下html代码: 电子邮件:电子邮件:`` 如标签所示,我有一个邮箱。我需要在mailto添加一封电子邮件,但是这封电子邮件会有所不同,所以我无法硬编码。我是从数据库中获取它的,所以我已经有了它,但是如何将它作为变量添加到html代码中呢 找到的所有示例都在mailto中硬编码了电子邮件:,因为您希望控制服务器端的值,因此我建议使用服务器控件,如下所示: <asp:HyperLink ID="HyperLink1" runat="server"

我必须修改以下html代码:

电子邮件:
电子邮件:``

如标签所示,我有一个邮箱。我需要在mailto添加一封电子邮件,但是这封电子邮件会有所不同,所以我无法硬编码。我是从数据库中获取它的,所以我已经有了它,但是如何将它作为变量添加到html代码中呢


找到的所有示例都在mailto中硬编码了电子邮件:

,因为您希望控制服务器端的值,因此我建议使用服务器控件,如下所示:

<asp:HyperLink ID="HyperLink1" runat="server" 
               NavigateUrl="mailto:abc@abc.com" 
               Text="abc@abc.com">
</asp:HyperLink>
// Get values from database
string emailAddress = GetEmailFromDatabase();
string subject = GetSubjctFromDatabase();

// Set NavigateUrl to use email address and subject values from above
HyperLink1.NavigateUrl = "mailto:" + emailAddress + "?subject=" + subject;

// You can also set the text of the hyper link here or in the markup
HyperLink1.Text = "Send email to " + emailAddress;

注意:标记有一个
NavigateUrl
值集,但您可以将其从标记中删除或保留,因为后面的代码将覆盖它。我只是说明属性存在,而不是试图用硬编码值来混淆您


将此添加到标记中:

<a id="mailtoLink" href="" runat="server">email</a>

尝试使用文字控件:

<asp:Literal id="emailLiteral" runat="server"></asp:Literal>
在您的aspx中

将你的锚的href设置为href=

类中的代码隐藏(不在方法中)

公共字符串destinationmail=“mailto:test@test.com“

然后,您可以将destinationEmail更改为您想要的任何内容

<asp:Literal id="emailLiteral" runat="server"></asp:Literal>
string emailColumn = YourGetEmailMethod()
emailLiteral.Text = "<a href=""mailto:" + emailColumn + """>Send mail to" + emailColumn + "</a>"