I am trying to receive an input for an e-mail address from a textbox in one .asp file called order.asp and then e-mail to that e-mail address using code in another .asp file called ordercomplete.asp (which uses CDO mail). The mailer works correctly if i specifically define ObjSendMail.To = someemail@provider.com, but not if i use a session variable such that ObjSendMail.To = Session("EmailSession") so that it's more dynamic. This is order.asp

<form id="form1" name="form1" method="post" action="ordercomplete.asp">
  <p>
    <label for="firstname">First Name:</label>
    <input type="text" name="firstname" id="firstname" />
    <%
    Session("EmailSession") = Request.Form("email")
    %>
  </p>
  <p>
    <label for="email">E-Mail Address:</label>
    <input type="text" name="email" id="email" />
  </p>
  <p>
    <input type="submit" name="submit" id="submit" value="Submit" />
  </p>
</form>
<p>&nbsp;</p>

In ordercomplete.asp, I tried to see if I can print the value that's been inputted in the email textbox in order.asp before I can go ahead and set ObjSentMail.To to the session variable. I tried to print and see if there is anything saved in Session("EmailSession")) at all using

<%
Response.Write(Session("EmailSession"))
%>

but it prints nothing. How can I get an inputted value from one asp file to transfer in this manner in another asp file?

Thanks.

有帮助吗?

解决方案

Change your inputs for AspNet textboxes. Change your input button for an AspNet button. Add a handler for the OnClick event. There, explicitly add the email from the textbox to the session object. The following code is not tested, so check it before using

protected void MyButton_Click(object sender, EventArgs e){
    Session.Add(txtEmail.Text);
    Response.Redirect("~/MyOtherPage.aspx");
}

其他提示

you are posting the form in order.asp to ordercomplete.asp. The form field email will only be available in the posted-to page, which you have given as ordercomplete.asp in the form action: action="ordercomplete.asp"

In ordercomplete.asp, you can get the value of the form field using Request.Form("email") .

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top