问题描述:

I want to use a Bootstrap form-horizontal in an .aspx page with a Site.Master page.

I get the error message that a form cannot be nested in another form.

I found several comments here that a Site.Master should not contain a form runat=server but every Visual Studio 2013 template I look at is set up that way and when I try to remove the form from the Site.Master I get an error:

asp:ScriptManager must be nested in a form.

I like the Bootstrap forms. Any work arounds?

网友答案:

You can add it using jQuery addClass for the .aspx page you need it for.

Use this on your individual pages.

<script>
    $(document).ready(function () {
        $("#form1").addClass("form-horizontal");
    });
</script>
网友答案:

You can't nest forms within forms in ASP.net. A Master Page will define the form tag and within that define a number of ContentPlaceHolders. Pages that then use the Master Page will then be have the option to place content within each of the defined place holders.

See how ASP.Net Master Pages work.

To use the BootStrap form-horizontal class just modify the Master Pages form tag e.g.

<form id="Form1" runat="server" class="form-horizontal">

You can of course have a selection of Master Pages (or nested Master Pages) to customise for each of your scenarios.

相关阅读:
Top