我的表单不能提交到指定的页面里面怎么办呢?我确定填写的没有问题action="savemessage.aspx",我在savemessage.aspx.cs里面Page_onload写的代码.
但是我在客户端看了html代码,action=自己,这是怎么回事呢?
但是我在客户端看了html代码,action=自己,这是怎么回事呢?
解决方案 »
- session 不活动是因为未注册 WebSessionActivator,或试图在 IHttpHandler 的构造函数中 访问session。
- 急!!asp.net mvc3 + iis6.0访问弹出windows用户登录窗口的问题
- 一个在asp中进行数据库查询的问题
- 这个效果是怎么实现的?
- 怎样在ASP.NET中连接MySQL数据库
- Vs2005的新建项中没有web窗体,怎么办
- 问一个关于构建ASP.NET网站的问题
- 服务器怎样防止Asp.Net用Process列出进程信息?
- ==如何在asp.net中动态新建VFP(.DBF)文件(在线)==
- 问一个DB2中的sqlcommand和Sqlserver中的区别
- 最近拿Ajax做个一个无刷新的网站,大家体验一下效果,随便PP
- *︻$▅▆▇◤ (36分捉拿高手)关于utf-8与gb2312的转换关系
如果是vs2005要提交到其它页面,可以设置其PostbackUrl属性
要想 action 到别的页。
form 不能 runat=server
if (!Page.IsPostBack)
{
string name = Request.Form["myname"].ToString();
string content = Request.Form["content"].ToString();
OleDbConnection conn = function.myconnection();
function ft = new function();
string sql = "insert into message([name],content,ip) values('" + name + "','" + function.htmlencode(content) + "','" + ft.ip() + "')";
try
{
OleDbCommand cmd = new OleDbCommand(sql, conn);
cmd.ExecuteNonQuery();
}
catch
{
conn.Close();
ft.error("出现了错误,服务器已经关闭!");
}
finally
{
conn.Close();
Response.Write("<script>alert('发表成功');location.href='default.aspx';</script>");
Response.End();
}
}
但 string name = Request.Form["myname"].ToString();说是空的,怎么回事呢?
// Get the value of TextBox1 from the page that
// posted to this page.
text = ((TextBox)PreviousPage.FindControl("TextBox1")).Text;
// Check for an empty string.
if (text != "")
PostedLabel.Text = "The string posted from the previous page is "
+ text + ".";
else
PostedLabel.Text = "An empty string was posted from the previous page.";
查查帮助,搜索:postbackurl,里面写的很清楚……
<head runat="server">
<title>我要留言</title>
</head>
<body>
<form id="form1" runat="server" method="post" action="add.aspx">
<div>
<table>
<tr>
<td style="width: 126px">
我的名字</td>
<td style="width: 429px">
<asp:TextBox ID="myname" runat="server"></asp:TextBox>
<asp:requiredfieldvalidator id="validator1" runat="server" controltovalidate="myname" errormessage="姓名必须输入" display="static"></asp:requiredfieldvalidator> </td>
</tr>
<tr>
<td style="width: 126px; height: 242px;">
我想说</td>
<td style="width: 429px; height: 242px;">
<asp:TextBox id='content' textmode='multiline' rows='8' runat='server' Height="204px" Width="419px"></asp:TextBox><asp:requiredfieldvalidator id="Requiredfieldvalidator2" runat="server" controltovalidate="content" errormessage="必须输入讲话内容" display="static"></asp:requiredfieldvalidator></td>
</tr>
<tr><td>
<asp:Button ID="Submit" runat="server" Text="发表讲话" /></td>
<td>
<asp:Button ID="Reset" runat="server" Text="重新输入" /></td>
</tr>
</table>
</div>
</form>
</body>
</html>
string content = this.content.text
//数据库操作写在Submit_Click事件中!