简体   繁体   中英

Calling an ASP.NET page from a form

I have a static page that contains a form.

<form METHOD="post" ACTION="...">           
  <input type="submit" value="Verzenden"  />        
</form>

When the submit button is clicked, I want the form fields to be sent to an ASP.NET page, in which I receive the form fields and do something with them (like sending a mail).

I was thinking to do something like this:

<form METHOD="post" ACTION="http://localhost:3384/mail.aspx">           
  <input type="submit" value="Verzenden"  />        
</form>

But how can I receive this data in the mail.aspx code behind?

Thanks

Just use the Request.Form collection:

string verz = Request.Form["Verzenden"];
etc...

Doing this in Page_Load is easiest. It's probably best to avoid having a typical postback form on that page, just to keep things simple; otherwise, you have to test for IsPostBack to make sure you should read the Form values.

<form action="Default.aspx" method="post">
<input type="text" name="fullname">
<select name="color">
    <option value="Red">Red $10.00</option>
    <option value="Blue">Blue $8.00</option>
    <option value="Green">Green $12.00</option>
</select>
<select name="size">
    <option value="Small">Small</option>
    <option value="Large">Large</option>
</select>
<input type="submit" value="Verzenden" />
</form>

在此输入图像描述

protected void Page_Load(object sender, EventArgs e)
{
    FullNameLabel.Text = Request.Form["fullname"];
    ColorLabel.Text = Request.Form["color"];
    SizeLabel.Text = Request.Form["size"];
}

在此输入图像描述

或者来自queryString Request.queryString["fieldname"];

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM