ASP.Net More than 1 form?

前端 未结 5 1694
既然无缘
既然无缘 2021-01-19 07:15

On every page (sitting in the master) I have the login fields.

In the other pages I have different controls, e.g. a contact formular.

How can I set more than

5条回答
  •  时光取名叫无心
    2021-01-19 08:11

    You can use validation groups to split a form into multiple logical forms, so that you can call validation in the Click event handlers for the buttons. This is really all you would need multiple forms for in ASP.Net, unless you were trying to avoid posting the data from all form fields back on postback.

    Try the following page sample:

    <%@ Page Language="C#" %>
    
    
    
    
        
    
    
        
    Username:
    Password:

    Contact

    Your name:
    Your email:
    Your message:

    Here you get validation, and it behaves as two seperate forms, although the data from both "forms" will be posted back.

    This is the standard paradigm for having multiple actions on a page, and has been around since ASP.Net 2 :).

    Please forgive the use of inline code, I thought it would make the example easier to follow.

提交回复
热议问题