Home > Article > Backend Development > Sharing of problems encountered in C# development
1. The constructor cannot have a return value type, because the constructor returns the object itself.
2. To convert a string into a date type, use the DateTime.Parese() or DateTime.ParseExact() function.
3. if(!Page.IsPostback){}
Use this function to make the web page only run the content of the function body when it is loaded for the first time. In the Page_Load() event, usually Can be used for initialization. If this function is not used, the content in the if() function body may be run again when some controls are posted back, resulting in the modified values of the related controls not being applied correctly.
4. The GridView field (BoundField) has an attribute HtmlEncode. This attribute is used to wrap HTML. If it is true (default value), the content in the field will be displayed as is. If it is false, the corresponding HTML tag in the field will be rendered. Therefore, to make the image link in the field appear, HtmlEncode="true" should be set.
5. How to format the date after getting it from the web page: Eval("wtDate", "{0:yyyy-MM-dd}")
But in DateTime.Now.Date The string formatting in .ToString("yyyy-MM-dd") is different.
6. NVarChar data type. In SQL SERVER 2005, there is NVarChar(max) type to represent a number up to 2^32, but this type is not supported in .net2.0. NVarChar can represent the maximum number. The number is still 4000 bytes.
7. Convert the string type to Guid type, and pass the string as a parameter of the Guid constructor.
For example: Guid gd = New Guid(string);
The empty value of Guid type is Guid.Empty, not null.
8. It is best to store values in each field. Even if it is not used, it is initialized to avoid data type mismatch when it is a null value, such as DateTime and uniqueIdentifier fields. Take out the null value. This can cause trouble when dealing with it.
9. To count the number of records, use a statement similar to the following:
int cout =(int)cmd.ExecuteScalar();
10. During the storage process, when wildcards are used in combination with parameters, string addition must be used instead of being placed directly on both sides of the parameters, as follows:
WHERE RTRIM(f.ftTitle) LIKE '%'+RTRIM(@ searchkey)+'%'
11. To obtain the value of an item in the list
For example, List Assuming that the ftIsResovled attribute is defined in the ftInfo class, then, to obtain the ftIsResolved value of item 0 of CurrentFault, you can obtain it through the language name: CurrentFault[0].ftIsResolved . 12. When the Input control contains labeled content (such as), the following errors may occur due to security issues: Description: The request verification process detected a potentially dangerous client input value, and the request The processing has been aborted. This value may indicate an attempt to compromise application security, such as a cross-site scripting attack. Request validation can be disabled by setting validateRequest=false in the Page directive or configuration section. However, in this case it is strongly recommended that the application explicitly checks all inputs. 13. Display the field content with HTML tags. If you need to render HTML tags, you can set the htmlencode attribute to true. When set to false, HTML tags within the field will be displayed as normal characters. You can also use the HtmlEncode() method to render HTML tags for field content. 14. The LoginStatus control can easily display the login status and provide shortcut links for login and logout. But sometimes it is inconvenient, especially when logging out and exiting the frame web page at the same time, using this control becomes powerless. You can directly use the LinkButton control. In the click event, add the following two sentences to log out and jump to the parent window of the frame web page: FormsAuthentication.SignOut(); Response .Write(""); 15. Close the window in C#: The above is the detailed content of Sharing of problems encountered in C# development. For more information, please follow other related articles on the PHP Chinese website!
Response.Write("");