在mailto超链接中使用声明的变量

时间:2022-11-15 21:53:38

I have a variable which is passed over from another C# class using the Request.QueryString[], now I want to take the value of that variable and use it in the mailto hyperlink. I don't want to hard code the email address.

我有一个变量,它使用Request.QueryString []从另一个C#类传递,现在我想获取该变量的值并在mailto超链接中使用它。我不想硬编码电子邮件地址。

The normal mailto link is:

正常的mailto链接是:

<a href"mailto:user1234@gmail.com: />

what I want to do is take the email provided by the user from a previous page...

我想要做的是从上一页获取用户提供的电子邮件...

I have: Request.QueryString["newEmail"];

我有:Request.QueryString [“newEmail”];

I tried this: <a href="mailto:Request.QueryString["newEmail"]" />

我试过这个:

but it doesn't work, please help!!!!

但它不起作用,请帮助!!!!

2 个解决方案

#1


1  

Use asp:HyperLink which gets rendered as the anchor tag.

使用asp:HyperLink作为锚标记呈现。

'Example:

'例:

<asp:HyperLink ID="EmailLink" runat="server"
        NavigateUrl='<% "mailto:" + Request.QueryString["newEmail"] %>'>
    Send Mail
</asp:HyperLink>

#2


0  

I have: RequestQueryString["newEmail"];

我有:RequestQueryString [“newEmail”];

Should be Request.QueryString["newEmail"].

应该是Request.QueryString [“newEmail”]。

Your question doesn't show where you're passing this "newEmail" to the query string.

您的问题没有显示您将此“newEmail”传递给查询字符串的位置。

I tried this: <a href="mailto:RequestQueryString["newEmail"]" />

我试过这个:

Unless that's a back-end string, you can't combine front-end and back-end code like this. You'd need to wrap it with <% %>, and even then you'd not do this because you'd need checks on whether the query string contains a value.

除非这是一个后端字符串,否则你不能像这样组合前端和后端代码。您需要用<%%>包装它,即使这样您也不会这样做,因为您需要检查查询字符串是否包含值。

Back-end:

后端:

protected string email = "";

public string GetEmail() {
    return email;
}

protected virtual void Page_Load(object sender, EventArgs e) {
    if (Request.QueryString["newEmail"] != null)
        email = Request.QueryString["newEmail"];
}

Front-end:

前端:

<a href="mailto:<%# GetEmail() %>"></a>

#1


1  

Use asp:HyperLink which gets rendered as the anchor tag.

使用asp:HyperLink作为锚标记呈现。

'Example:

'例:

<asp:HyperLink ID="EmailLink" runat="server"
        NavigateUrl='<% "mailto:" + Request.QueryString["newEmail"] %>'>
    Send Mail
</asp:HyperLink>

#2


0  

I have: RequestQueryString["newEmail"];

我有:RequestQueryString [“newEmail”];

Should be Request.QueryString["newEmail"].

应该是Request.QueryString [“newEmail”]。

Your question doesn't show where you're passing this "newEmail" to the query string.

您的问题没有显示您将此“newEmail”传递给查询字符串的位置。

I tried this: <a href="mailto:RequestQueryString["newEmail"]" />

我试过这个:

Unless that's a back-end string, you can't combine front-end and back-end code like this. You'd need to wrap it with <% %>, and even then you'd not do this because you'd need checks on whether the query string contains a value.

除非这是一个后端字符串,否则你不能像这样组合前端和后端代码。您需要用<%%>包装它,即使这样您也不会这样做,因为您需要检查查询字符串是否包含值。

Back-end:

后端:

protected string email = "";

public string GetEmail() {
    return email;
}

protected virtual void Page_Load(object sender, EventArgs e) {
    if (Request.QueryString["newEmail"] != null)
        email = Request.QueryString["newEmail"];
}

Front-end:

前端:

<a href="mailto:<%# GetEmail() %>"></a>