如何通过按钮单击将查询字符串传递给链接? [英] How can I pass query string to link from button click?

查看:61
本文介绍了如何通过按钮单击将查询字符串传递给链接?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好..我在将查询字符串(唯一ID)传递给超链接时遇到了问题。此超链接将作为特定收件人的电子邮件正文发送。按钮单击是发送包含超链接的电子邮件的功能。更具体地说,按钮位于网格视图中,每个行都有自己唯一的id和数据。意味着网格视图中的每一行都有自己的发送按钮。因此,当用户单击发送按钮时,它将发送具有特定行的唯一ID的超链接。当收件人单击超链接时,它将打开一个页面,该页面将查看唯一ID的数据。我希望你们明白我想说的是因为我正在寻找答案,因为我已经在互联网上进行了一整天的研究,但仍然无法解决。请帮忙。



我尝试了什么:



< asp :Button ID =sendbtnrunat =serverCommandName =SelectText =send/>



private void SendEmail(string uniqueid)
使用(HtmlTextWriter hw = new HtmlTextWriter sw))

{

GridView2.RenderControl(hw);

StringReader sr = new StringReader(sw.ToString());

// uniqueid = GenerateRandom.GetUniqueReferalid(14);

// string cid =tripid;

// string url =查看交易;

MailMessage mm = new MailMessage(adaniys93@gmail.com,adaniys93 @ gmail .com);

mm.Subject =GridView电子邮件;

mm.Body =< a href ='http:// localhost / businesstrip / PrintBusinessTrip .aspx?tripid =+ Request.QueryString [tripid]。ToString()+>登录;

mm.IsBodyHtml = true;

SmtpClient smtp = new SmtpClient();

smtp.Host =smtp.gmail。 com;

smtp.EnableSsl = true;

System.Net.NetworkCredential NetworkCred = new System.Net.NetworkCredential();

NetworkCred .UserName =addaniys93@gmail.com;

NetworkCred.Password =0;

smtp.UseDefaultCredentials = true;

smtp .Credentials = NetworkCred;

smtp.Port = 587;

smtp.Send(mm);

}

}

}

Hello.. I've got problem in passing query string(unique id) to hyperlink. This hyperlink will be send as an email body for a specific recipient. The button click is function to send email that contain the hyperlink. To be more specific, the button is place inside grid view where have its own unique id and data for every row. Mean that every row in grid view will have its own send button. So when user click on the send button it will send the hyperlink that have unique id for specific row. When recipient click on the hyperlink, it will open a page that will view the data of a unique id. I hope you guys understand what I'm trying to say because I'm dying looking for an answer as I have make research on internet for a whole day and it still not solve. Please help.

What I have tried:

<asp:Button ID="sendbtn" runat="server" CommandName="Select" Text="send" />

private void SendEmail(string uniqueid)
{
using (StringWriter sw = new StringWriter())
{
using (HtmlTextWriter hw = new HtmlTextWriter(sw))
{
GridView2.RenderControl(hw);
StringReader sr = new StringReader(sw.ToString());
//uniqueid = GenerateRandom.GetUniqueReferalid(14);
//string cid = "tripid";
//string url = "View Transaction";
MailMessage mm = new MailMessage("adaniys93@gmail.com", "adaniys93@gmail.com");
mm.Subject = "GridView Email";
mm.Body = "<a href='http://localhost/businesstrip/PrintBusinessTrip.aspx?tripid=" + Request.QueryString["tripid"].ToString() + " > login";
mm.IsBodyHtml = true;
SmtpClient smtp = new SmtpClient();
smtp.Host = "smtp.gmail.com";
smtp.EnableSsl = true;
System.Net.NetworkCredential NetworkCred = new System.Net.NetworkCredential();
NetworkCred.UserName = "addaniys93@gmail.com";
NetworkCred.Password = "0";
smtp.UseDefaultCredentials = true;
smtp.Credentials = NetworkCred;
smtp.Port = 587;
smtp.Send(mm);
}
}
}

推荐答案

试试



try

<asp:GridView ID="GridView1" runat="server"  OnRowCommand="GridView1_RowCommand"    >
              <Columns>
                  <asp:TemplateField> 
                      <ItemTemplate>
                          <asp:Button ID="sendbtn"  CommandArgument='<%# Eval("UniqueIDColumnName") %>'
    runat="server" CommandName="Select" Text="send" /> 
                      </ItemTemplate>
                  </asp:TemplateField>
              </Columns>
          </asp:GridView>










protected void GridView1_RowCommand(object sender, GridViewCommandEventArgs e)
       {
           if (e.CommandName == "Select")
           {
               var uniqueId =Convert.ToString( e.CommandArgument);
               SendEmail(uniqueId);
           }
       }


这篇关于如何通过按钮单击将查询字符串传递给链接?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆