0

form runat="server"どうやら1ページに1つしか持てません。

私のページには1つのフォームがあり、名前のリストに読み込まれます。このフォームでは、リストに新しい名前を追加することもできます。

リストビューの各名前にonclickイベントを添付しました。それをクリックすると、JavaScriptコードを使用してデータを編集フォーム(追加フォームの横)にロードする必要があります。私はこれをうまくやることができます。

しかし、ページ上で2つのフォームを持つように構成するにはどうすればよいですか?

イラスト:

<table>
    <tr>
        <td style="width:50%;" valign="top">

            <form runat="server" action="productCats.aspx?action=new&mid=2">
                <div class="subHead">Create New Category</div>
                <table class="settingTable">
                    <tr>
                        <td colspan="2"><b>Category Name</b></td>
                    </tr>
                    <tr>
                        <td>
                            <asp:TextBox ID="catName" runat="server" CssClass="tbox widebox"></asp:TextBox>
                            <asp:RequiredFieldValidator runat="server"
                                      id="ValidatorName"
                                      ControlToValidate="catName"
                                      ErrorMessage="You need to enter a category name"
                                      display="Dynamic" />
                        </td>
                    </tr>
                    <tr>
                        <td>This is the name of your category.</td>
                    </tr>
                    <tr>
                        <td colspan="2"><b>Parent Category</b></td>
                    </tr>
                    <tr>
                        <td>
                            <asp:ListBox SelectionMode="Single" Rows="8" id="parent" runat="server" CssClass="tbox widebox">
                                <asp:ListItem Selected="True" Text="Top Level" Value="0"></asp:ListItem>
                            </asp:ListBox>
                            <asp:RequiredFieldValidator runat="server"
                                      id="RequiredFieldValidator1"
                                      ControlToValidate="parent"
                                      ErrorMessage="You need to select a parent"
                                      display="Dynamic" />
                        </td>
                    </tr>
                    <tr>
                        <td>Choose a parent this category belongs to.</td>
                    </tr>
                </table>
                <asp:Button id="id" text="Create" runat="server" />
            </form>
        </td>
        <td style="width:4%;">
        </td>
        <td valign="top">
        <div class="subHead">Modify Category</div>

            <form id="Form1" action="productCats.aspx?action=update&mid=2">
                <table class="settingTable">
                    <tr>
                        <td colspan="2"><b>Category Name</b></td>
                    </tr>
                    <tr>
                        <td>
                            <asp:TextBox ID="newCatName" runat="server" Enabled="false" CssClass="tbox widebox"></asp:TextBox>
                            <asp:RequiredFieldValidator runat="server"
                                      id="RequiredFieldValidator2"
                                      ControlToValidate="newCatName"
                                      ErrorMessage="Enter a new category name"
                                      display="Dynamic" />
                        </td>
                    </tr>
                </table>
            </form>
        </td>
    </tr>
</table>
4

2 に答える 2

1

ASP.NET Webフォームは、ページに要素を1つだけ<form>配置し、何かが変更されるたびにこれを同じページにポストバックすることで機能します(ポストバック)。複数のフォームを使用しようとし、フォーム要素にカスタムaction属性を指定することは、フレームワークが機能するように設計されていることに反します。これは決して良い考えではありません。

<form>2番目の要素を削除actionし、最初の要素から属性を削除しようとします<form><table>また、すべてがフォーム内にある場合、つまりページの上部にあるタグがある場合、ASP.NETははるかに幸せになります。

ページが何をしているのかわかりませんが、を持ってTextBoxいて、このコンテンツを使用してアイテムをに追加しているListBox場合、よりWebフォームに似たアプローチは、何らかのコントロールを使用してポストバックを実行することです。が入力されたら、をある種のデータソースにTextBox再バインドします。Ajaxポストバックが必要な場合はListBox、おそらくを使用してください。UpdatePanel

JavaScriptとクエリ文字列パラメータに慣れている場合は、ASP.NETMVCの方が適している可能性があります。

于 2010-08-25T09:08:21.583 に答える
0

あなたの説明から私が理解したことによると、あなたはあなたのこのページに機能が必要です。リスト内のリストアイテムの1つをクリックすると、form2の要素が表示され、詳細を変更する必要があります...私が思うに... 2つのパネルを使用し、リストボックス内のアイテムをクリックすると、編集パネルを表示でき、詳細の変更やボタンクリックなどの他のイベントで..変更された詳細を含むリストボックスパネルを表示できます。

はい、Grahamが述べたように、これを実現するためにAjax更新パネルを使用できます。

于 2013-02-08T17:59:21.033 に答える