First, let's take a look at the interface.
Interface requirements:
1. Click "create section" to save the input text in the text box to the database;
2. Click "edit" in the gridview to enter the record information in the text box;
3. The Service Code corresponds to the table field sectioncode that cannot be empty, and the ID is "tbsectionid ";
4. Add a requiredfieldvalidator, controltovalidate = "tbsectionid ";
Problems starting to tangle
First, set the enableclientscript of requiredfieldvalidator to true so that requiredfieldvalidator can be verified by the client.
Click the button to trigger the authentication and prompt that the sectionid cannot be blank to meet the requirements. However, clicking "edit" in the gridview will also trigger verification, so that the record information cannot be filled with the control.
Cause Analysis: enableclientscript = true, requiredfieldvalidator is used for client verification. Click "edit" to trigger client verification. In this case, the sectionid value is empty and verification fails, therefore, it cannot be uploaded back to the server, and therefore the text box cannot be filled with content.
Then, set the enableclientscript of requiredfieldvalidator to false to cancel client verification.
Click the button to prompt that the verification fails, but the content can be saved to the database. Click Edit. It also prompts that the verification fails, but the text box is filled successfully.
Cause of analysis: If requiredfieldvalidator's enableclientscript is set to false, the verification is performed on the server side. The verification is performed based on the sectionid value. If the verification fails, the isvalid of the page is set to false and the error message is displayed, however, the code on the server is executed later.
Solution: Add code to determine the verification result. The Event Response Function of the button is written in the following form:
Protected void onbutton_clicked (Object sender, eventargs E)
{
If (page. isvalid)
{
// Button event processing logic
....
}
}
(Note: personal opinions. If any error occurs, please do not hesitate to advise)