Reputation: 3
I'm trying to build html page with 2 forms in it, that both of them will run at server, how can I do that, or there is something else I can do instead?
Thanks. (Tell me if you want to see the code).
Upvotes: 0
Views: 622
Reputation: 1751
I noticed you just said ASP .NET instead of picking a specific ASP .NET technology: WebForms or MVC.
In WebForms, unfortunately not. However, you can create an asp:Panel and use the DefaultButton attribute to contain the scope of each separate form.
In MVC, it's extremely easy since you use the Form tag. In ASP.NET MVC you can implement as many forms as you want (and it is valid & correct behavior of web pages).
EDIT:For comment
<asp:Panel ID="Panel1" runat="server" DefaultButton = "Button1">
<asp:Button ID="Button1" runat="server" Text="Button" OnClick = "Button1_Click" />
<asp:Button ID="Button2" runat="server" Text="Button" OnClick = "Button2_Click" />
<asp:Button ID="Button3" runat="server" Text="Button" OnClick = "Button3_Click" />
<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
</asp:Panel>
Like this you can use more than one panel on the same page for some group of server control and you can set DefaultButton
for handling server side event.
The same can be done from code behind
C#
Panel1.DefaultButton = "Button1";
VB.Net
Panel1.DefaultButton = "Button1"
Default Button property ensures that whenever user presses Enter key the button that is set as default will be triggered.
Upvotes: 1