Form tag in .Net doesn't work if alone
I have just create a blank .net web form page and added a simple html form, it reads:
<body>
<form id="form1" runat="serv开发者_运维百科er">
<div>
<form method="post" action="2ndpage.aspx">
<input type="text" name="Value" />
<input type="submit" value="click" />
</form>
</div>
</form>
</body>
If I click the button I'm not taken to 2ndpage.aspx. But If I add "<form></form>
" just after the <div>
so that the body now reads:
<body>
<form id="form1" runat="server">
<div>
<form></form>
<form method="post" action="2ndpage.aspx">
<input type="text" name="Value" />
<input type="submit" value="click" />
</form>
</div>
</form>
</body>
it works and I'm taken to 2ndpage.aspx when click.
I can look at this for another month but I'm sure I couldn't see where the bug is, I'd need a pair of fresh eyes. Any ideas? Thanks
you cant place form inside another form!
There's a good article here - https://web.archive.org/web/20170420110433/http://anderwald.info/internet/nesting-form-tags-in-xhtml/
It discusses not being able to nest one form in another form and also deals specifically with the scenario you describe.
You can't have nested form tags.
I'm not quite sure why it works when you add another empty form tag. But my guess is that the parser simply ignores the start of the tag and sees the end tag as the end tag for the first form. And therefore doesn't see it as nested forms anymore.
精彩评论