以前曾经尝试过,但是失败,最近才发现的。
关键在html中:
如果元素被提交到aspx后台,元素必须至少有name属性:<input type="text" name="txtName" />
后台访问时候的方法是 string name = Request.Form["txtName"];
html文件:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head></head>
<body>
<center>
<br /> <br />
<div>
在此处输入,页面提交到了WebForm3.aspx中。
<br />
<span style="color: Red;">提交的窗体中的控件若被后台访问到则“一定要有name属性,是否有id属性无所谓”</span>
</div>
<form action="WebForm3.aspx" method="post">
<div> name:<input id="txtName" name="txtName" type="text" /><span id="CheckName"></span></div>
<div> pwd: <input name="txtPwd" type="password" /></div>
<div> city: <select name="selectCity"> <option value="beijing">北京</option> <option value="shanghai">上海</option> </select> </div>
<div> sex: <input type="radio" name="radioSex" value="male" />男 <input type="radio" name="radioSex" value="female" />女</div>
<div> <input id="file1" name="file1" type="file" /></div> <input id="Submit1" type="submit" value="submit" />
</form> </center></body></html>
WebForm3.aspx.cs文件:
protected void Page_Load(object sender, EventArgs e)
{
string name = Request.Form["txtName"];
string pwd = Request.Form["txtPwd"];
string city = Request.Form["selectCity"];
string sex = Request.Form["radioSex"];
string file = Request.Form["file1"];
Response.Write("您输入了:" + name + "<br />"+pwd+"<br />"+city+"<br />"+sex+"<br />"+file+"<br />"); Response.Write(DateTime.Now.ToString("yyyy-MM-dd HH-mm-ss"));
}