我从当前页面post到一个页面,为什么老是不停的在当前页面刷新,无法进行跳转
<%@ Page Language="C#" AutoEventWireup="true"  CodeFile="Default.aspx.cs" Inherits="_Default"%><!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" method="post" action="LoadXML.aspx" runat="server">     
    <div>
        <input type="hidden" runat="server" id="hi_xml" name="hi_xml"/>
    </div>    
    </form>
      <script type="text/javascript">
            document.form1.submit();
    </script>    
</body>
</html>后台代码:
using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Text;public partial class _Default : System.Web.UI.Page 
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            StringBuilder strXML = new StringBuilder();
            strXML.Append("<?xml version=\"1.0\" encoding=\"utf-8\"?>");
            strXML.Append("<Game>");
            strXML.Append("<Name>张三</Name>");
            strXML.Append("<Number>1000</Number>");
            strXML.Append("</Game>");
            hi_xml.Value = Server.HtmlEncode(strXML.ToString());
        }
    }
   
}

解决方案 »

  1.   

    <form id="form1" method="post" action="LoadXML.aspx" runat="server">  
    红色去掉
      

  2.   

     <script type="text/javascript"> 
                document.form1.submit(); 
        </script>   
    这段代码没有开关来决定是否执行,每次页面进来就会执行,然后提交刷新页面,刷新页面就提交刷新页面,刷新页面就提交刷新页面,刷新页面就提交刷新页面刷新页面就提交刷新页面刷新页面就提交刷新页面刷新页面就提交刷新页面。,如此一直死循环。
      

  3.   

    然后我记得runat server的话,指定action没有用的,还是会递交到本页面
      

  4.   

          <script type="text/javascript">             document.form1.submit(); 
        </script>    
    如歹也要window.onload后执行这行脚本吧
    window.onload=function()
    {
    document.form1.submit(); 
    }
      

  5.   

          <script type="text/javascript"> 
                document.form1.submit(); 
        </script>    
    这句话相当于window.onload中执行,问题在此
      

  6.   

    我是想页面加载以后,处理完后台的代码就跳转到我action的页面
      

  7.   

     document.form1.submit(); 这个的原因造成的,把<form id="form1" method="post" action="LoadXML.aspx" runat="server">    
    中的改为<form id="form1" method="post" runat="server">    在Page_Load中
     
           if (!IsPostBack) 
           {               StringBuilder strXML = new StringBuilder(); 
                strXML.Append(" <?xml version=\"1.0\" encoding=\"utf-8\"?>"); 
                strXML.Append(" <Game>"); 
                strXML.Append(" <Name>张三 </Name>"); 
                strXML.Append(" <Number>1000 </Number>"); 
                strXML.Append(" </Game>"); 
                hi_xml.Value = Server.HtmlEncode(strXML.ToString()); 
               
                // 
                Response.Redirect("LoadXML.aspx"); //LoadXML.aspx?name=**&Number=** 传参数 
           } 
      

  8.   

      
    document.form1.submit(); 该为
    window.open("LoadXML.aspx");
      

  9.   

    用Response.Redirect()在地址栏上能显示内容啊,我想用post,不在地址栏上显示内容
      

  10.   

    把runat="server"去掉的话,就报脚本错误~~~~
      

  11.   

    <form id="form1" method="post" action="LoadXML.aspx">
    <script>
    document.getElementById('form1').submit();
    </script>
      

  12.   

    document.getElementById('form1').submit(); 
    还是一样啊,不停的刷页面
      

  13.   

    <form id="form2" method="post" action="LoadXML.aspx" target="_self">再改一下,如果这样还不行就没办法了,因为前面的经测试都可以,关键是为啥你不行
      

  14.   

    <head id="Head1" runat="server"> 
        <title>上传中。 </title>  
    </head> 
    <body onload="javascript:document.getElementById('form1').submit();"> 
        <form id="form1" method="post" action="LoadXML.aspx">    
        <div> 
            <input type="hidden" runat="server" id="hi_xml" name="hi_xml" value="<%=test %>"/>
        </div>    
        </form>   
    </body> 
    </html> 
    后台:
    using System;
    using System.Data;
    using System.Data.SqlClient;
    using System.Configuration;
    using System.Web;
    using System.Web.Security;
    using System.Web.UI;
    using System.Web.UI.WebControls;
    using System.Web.UI.WebControls.WebParts;
    using System.Web.UI.HtmlControls;using System.Text;public partial class _Default : System.Web.UI.Page
    {
        protected string test;
        protected void Page_Load(object sender, EventArgs e)
        {
            StringBuilder strXML = new StringBuilder();
            strXML.Append(" <?xml version=\"1.0\" encoding=\"utf-8\"?>");
            strXML.Append(" <Game>");
            strXML.Append(" <Name>张三 </Name>");
            strXML.Append(" <Number>1000 </Number>");
            strXML.Append(" </Game>");
            test = Server.HtmlEncode(strXML.ToString());     }
    }
      

  15.   

    还没有学到··
    还在学oop.net