ASP.NET页面Form嵌套解决方法

Default.aspx:
<%@ Page Language="C#" %>

<!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 id="Head1" runat="server">
    <title>ASP.NET页面Form嵌套解决方法-Mzwu.Com</title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        <form name="form2" action="http://www.mzwu.com/">
            <input type="text" name="price" value="100" />
            <input type="submit" value="pay" />
        </form>
        <form name="form3" action="http://www.mzwu.com/">
            <input type="text" name="price" value="200" />
            <input type="submit" value="pay" />
        </form>
        <form name="form4" action="http://www.mzwu.com/">
            <input type="text" name="price" value="300" />
            <input type="submit" value="pay" />
        </form>
    </div>
    </form>
</body>
</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 id="Head1"><title>
    ASP.NET页面Form嵌套解决方法-Mzwu.Com
</title></head>
<body>
    <form name="form1" method="post" action="default.aspx" id="form1">
<div>
<input type="hidden" name="__VIEWSTATE" id="__VIEWSTATE" value="/wEPDwUJNzgzNDMwNTMzZGThdDmLdPdmCmhu1omEmclCkB5Reg==" />
</div>

    <div>
        <form name="form2" action="http://www.mzwu.com/">
            <input type="text" name="price" value="100" />
            <input type="submit" value="pay" />
        </form>
        <form name="form3" action="http://www.mzwu.com/">
            <input type="text" name="price" value="200" />
            <input type="submit" value="pay" />
        </form>
        <form name="form4" action="http://www.mzwu.com/">
            <input type="text" name="price" value="300" />
            <input type="submit" value="pay" />
        </form>
    </div>
    </form>
</body>
</html>

form1是ASP.NET自带的,由于它的存在,form2无法正常提交,点击submit按钮,表单将提交到Default.aspx页面(form3,form4能正常提交),解决方法如下:

<%@ Page Language="C#" %>

<!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 id="Head1" runat="server">
    <title>ASP.NET页面Form嵌套解决方法-Mzwu.Com</title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        <form name="form2">
            <input type="text" name="price" value="100" />
            <input type="submit" value="pay" onclick="this.form.action='http://www.mzwu.com/'" />
        </form>
        <form name="form3">
            <input type="text" name="price" value="200" />
            <input type="submit" value="pay" onclick="this.form.action='http://www.mzwu.com/'" />
        </form>
        <form name="form4">
            <input type="text" name="price" value="300" />
            <input type="submit" value="pay" onclick="this.form.action='http://www.mzwu.com/'" />
        </form>
    </div>
    </form>
</body>
</html>


评论: 0 | 引用: 0 | 查看次数: 7480
发表评论
登录后再发表评论!