gpt4 book ai didi

c# - 从代码隐藏(或前端)设置 mailto

转载 作者:太空狗 更新时间:2023-10-30 00:52:43 24 4
gpt4 key购买 nike

我必须遵循 html 代码:

Email:&nbsp;<a href="mailto:...?subject=subject"><asp:Label style="margin-right: 90px;" ID="EmailLabel"
CssClass="InfoData" runat="server" Text="E-mail"></asp:Label></a>
电子邮件: ``

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

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

最佳答案

既然你想控制服务器端的值,那么我建议使用服务器控件,像这样:

<asp:HyperLink ID="HyperLink1" runat="server" 
NavigateUrl="mailto:abc@abc.com"
Text="abc@abc.com">
</asp:HyperLink>

NavigateUrlText 是您希望在代码隐藏中与之交互的属性,如下所示:

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

Note: The markup has a NavigateUrl value set, but you can remove it from the markup or just leave it, as the code-behind will overwrite it. I was just showing that the property exists, not trying to confuse you with hardcoding a value.

关于c# - 从代码隐藏(或前端)设置 mailto,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20223003/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com