我尝试在创建新工单后从我的webform1发送电子邮件,但是当用户单击工作订单号时,我希望将工作订单号作为参数传递给webform2。我用来发送电子邮件的代码:
System.Net.Mail.MailMessage mm = new System.Net.Mail.MailMessage();
mm.From = new System.Net.Mail.MailAddress("some@some.com");//who send
mm.To.Add(new System.Net.Mail.MailAddress("some@gmail.com"));
mm.To.Add(new System.Net.Mail.MailAddress("some@some.com"));
mm.Subject = "WorkOrders Created With Type Safety";
mm.Body = "WorkOrderNumber" + ": "
+ "<a href=\"http://localhost:49695/Safety.aspx?=WorkOrderNum=\">"
+ TextBox13.Text + "</a>"
+ "<-Click on the Work Order Number" + "<br><br/>"
+ "Requestor" + ": " + TextBoxRequestor.Text
+ "<br><br/>" + "Date" + ": " + TextBoxDate.Text
+ "<br><br/>" + "Department" + ": " + TextBoxDepartment.Text
+ "<br><br/>" + "Completion Date" + ": "
+ TextBoxCompletionDate.Text + "<br><br/>" + "Machine Description"
+ ": " + TextBoxMachineDescription.Text + "<br><br/>"
+ "Machine Location" + ": " + TextBoxMachineLocation.Text
+ "<br><br/>" + "Work Required" + ": " + TextBoxWorkRequired.Text
+ "<br><br/>" + "Status" + ": " + TextBoxStatus.Text;
mm.IsBodyHtml = true;
System.Net.Mail.SmtpClient client = new System.Net.Mail.SmtpClient();
client.Host = ConfigurationManager.AppSettings["smtpServer"];
client.Send(mm);
当上述代码作为电子邮件发送时,结果如下所示,14是可点击链接:
WorkOrderNumber: 14<-Click on the Work Order Number
Requestor: Mark
Date: 01/07/2015
Department: IT
Completion Date: 01/08/2015
Machine Description: Fan
Machine Location: SomeLocation
Work Required: Needs Installing
Status: Open
然后在webform2上我可以使用它:
protected void Page_Load(object sender, EventArgs e)
{
var workourdernum = Request.QueryString["WorkOrderNum"];
}
所以我只想将TextBox13.Text中的那个数字与链接一起传递,我在网上查看人们正在通过Response.Redirect()
完成类似的任务答案 0 :(得分:1)
这会有用吗?
"<a href=\"http://localhost:49695/Safety.aspx?WorkOrderNum=" +
+ TextBox13.Text + "\">" + TextBox13.Text + "</a>"
+ "<-Click on the Work Order Number" + "<br><br/>"
您将在查询字符串中传递工单号。然后,您的网页可以从查询字符串中提取工单号。
您将获得如下所示的HTML:
<a href="http://localhost:49695/Safety.aspx?WorkOrderNum=123">123</a>
您已拥有的代码(对于Page_Load
)可以完美地在第二页中提取工单号。
答案 1 :(得分:0)
以下是如何将值从一个表单传递到另一个表单的示例。
webform1.aspx - 例如按钮点击事件
Response.Redirect("webform2.aspx?number=" + TextBox13.Text);
webform2.aspx
int passedNumber;
protected void Page_Load(object sender, EventArgs e)
{
if (Request["number"] != null)
{
passedNumber = Convert.ToInt32(Request["number"]);
}
}
现在,您可以在webform2上使用该号码执行任何操作。