I am making an asp.net website and I have a button on the main WebForm that it is hyperlinked with WebForm2.
The WebForm2 that opens is a typical contact form that contains some text boxes, drop down lists and a button that sends an e-mail with the information that I entered. But because I am making an e-commerce website, depending on which button(on which product) is clicked on the main WebForm, I need to autofill the TextBox that contains the "Product Name" on the WebForm2.
Firstly, I had a JavaScript modal that was opened when the button was clicked, and I made independent forms with different value on the TextBox depending on the Product Name, but I could not figure out how to make the modal functional to send an e-mail, simply the information that was entered could not be proceed an the
e-mail that I get was only the mail_message text (ex. Name: , Surname: and Telephone Number: were blank) but not the text that was filled in the form.
So my question is, how to make the button on the main WebForm autofill the TextBox on the WebForm2 that contains the Product Name?
In case it matters, on the WebForm2 the code that sends me an e-mail is:
protected void button_Click(object sender, EventArgs e)
{
try
{
var from = "email";
var to = "secondemail";
const string Password = "password";
string mail_subject = txt_subject.Text.ToString();
string mail_message = "Your Name: " + txt_name.Text + "\n";
mail_message += "Your Surname: " + txt_surname.Text + "\n";
mail_message += "Your telephone number: " + txt_phone.Text + "\n";
mail_message += "Your address: " + txt_address.Text + "\n";
mail_message += "Your e-mail: " + txt_email.Text + "\n";
mail_message += "The product name: " + txt_product.Text + "\n";
mail_message += "Payment method: " + dropdownlist.SelectedValue + "\n";
var smtp = new SmtpClient();
{
smtp.Host = "smtp@mail";
smtp.Port = port;
smtp.EnableSsl = true;
smtp.DeliveryMethod = SmtpDeliveryMethod.Network;
smtp.Credentials = new NetworkCredential(from, Password);
smtp.Timeout = 20000;
}
smtp.Send(from, to, mail_subject, mail_message);
confirm.Text = "Thank you for your order, our team will deliver the product you ordered at your home address as soon as possible.";
txt_subject.Text = "";
txt_name.Text = "";
txt_surname.Text = "";
txt_phone.Text = "";
txt_address.Text = "";
txt_email.Text = "";
txt_subject.Text = "";
txt_product.Text = "";
dropdownlist.SelectedIndex = -1;
}
catch (Exception)
{
confirm.Text = "The order can't be proceed at the moment, please try again later.";
confirm.ForeColor = Color.Red;
}
Cheers, grateful for any help.