我的表单不能提交到指定的页面里面怎么办呢?我确定填写的没有问题action="savemessage.aspx",我在savemessage.aspx.cs里面Page_onload写的代码.
但是我在客户端看了html代码,action=自己,这是怎么回事呢?

解决方案 »

  1.   

    你不是用服务器控件的吗?
    如果是vs2005要提交到其它页面,可以设置其PostbackUrl属性
      

  2.   

    如果是vs2003下只能提交到本页,被称为Postback
      

  3.   

    如果你的提交按钮是服务器的控件,就要在事件里面写:Response.Redirect
      

  4.   

    你的 <form> 如果是runat="server"的。它的 action 只能是本页。
    要想 action 到别的页。
    form 不能 runat=server
      

  5.   

    我用的是vs 2005,我的接收代码是这么写的
     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();说是空的,怎么回事呢?
      

  6.   

    string text;
        
        // 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.";
      

  7.   

    ms-help://MS.VSCC.v80/MS.MSDN.v80/MS.NETDEVFX.v20.chs/cpref16/html/P_System_Web_UI_WebControls_Button_PostBackUrl.htm
    查查帮助,搜索:postbackurl,里面写的很清楚……
      

  8.   

    把前面的Html代码也发来看看~
      

  9.   

    <%@ Page Language="C#" AutoEventWireup="true" CodeFile="add.aspx.cs" Inherits="abing.test.add" %><!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 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>
      

  10.   

    起初我在Submit加了点击事件,但是不行,达不到目的。
      

  11.   

    string name = this.myname.text
     string content = this.content.text
    //数据库操作写在Submit_Click事件中!