Some considerations and tips in. NET development

Source: Internet
Author: User
Tags date format object datetime html tags net string format window

1. Constructors cannot bring return value types because constructors return is the object itself.

2, convert the string to date type, with Datetime.parese () or DateTime. ParseExact () function.

3, if (! Page.IsPostBack) {}

Use this function to make a Web page run the contents of the function body only on first load, and in the Page_Load () event, which is typically used for initialization. If you do not use this function, you may run the contents of the if () function again when some controls return, causing the modified value of the associated control to not be properly applied.

4, the GridView field (BoundField) has a property htmlencode. This property is used to wrap HTML, and if True (the default), the contents of the field are displayed as-is. If False, the corresponding HTML tags in the field are rendered. For this reason, you should set htmlencode= "true" if you want the picture links in the field to be displayed.

5, the Web page after the date to format the method: Eval ("Wtdate", "{0:YYYY-MM-DD}"), but in DateTime.Now.Date.ToString ("Yyyy-mm-dd") the string format is different.

6, nvarchar data type, in SQL SERVER 2005 with nvarchar (max) type to represent the largest number of 2^32, but in. net2.0 does not support this type, the maximum number of nvarchar can still represent 4000 bytes.

7. Converts a string type to a GUID type, which can be passed as a parameter of a GUID constructor.

such as: GUID GD = New GUID (string);

The null value for the GUID type is guid.empty, not null.

8, it is best to store the value of each field, even if not used, the initial settings to avoid a null value, the occurrence of data type mismatch phenomenon, such as Datetime,uniqueidentifier field, remove null value for processing will bring trouble.

9, statistics on the number of records, using a statement similar to the following:

int cout = (int) cmd. ExecuteScalar ();

10, stored in the process, wildcard characters and parameters used in combination, to use string addition, but not directly on both sides of the parameters, as follows:

WHERE RTRIM (f.fttitle) like '% ' +rtrim (@searchkey) + '% '

11, to get the value of an item in the List<t> object, you can use the following method:

such as list<ftinfo> Currentfault = new list<ftinfo> ();//Create an Object

Assuming the ftisresovled attribute is defined in the Ftinfo class, the ftisresolved value of the No. 0 item of the Currentfault can be obtained by using the name: currentfault[0].ftisresolved.

12. When the input control contains tagged content (for example), there may be errors due to security issues: Description: The request verification process detects potentially dangerous client input values and the processing of the request has been aborted. This value may indicate an attempt to compromise the security of an application, such as a cross-site scripting attack. You can disable request validation by setting Validaterequest=false in the Page directive or configuration section. However, in this case, it is strongly recommended that the application explicitly check all input.

13, display the content of the field with HTML tags, if you need to render HTML tags, you can set the HTMLEncode property to True. When set to False, the HTML tags in the field are displayed as normal characters. You can also use the HTMLEncode () method to render HTML tags for the contents of a field.

14. The LoginStatus control makes it easy to display login status and provides quick links to login and logoff. But sometimes it's not convenient, especially when you want to exit the frames page while you're out of the frame, you're powerless to use the control. You can use the LinkButton control directly, in the Click event, add the following two sentences, you can achieve logout while jumping to the frame page of the parent window:

FormsAuthentication.SignOut ();
Response.Write ("<script language=javascript> window.open". /default.aspx ', target= ' _top ') </script> ");

15, C # Close the window:

Response.Write ("<script language:javascript>javascript:window.close ();</script>");



Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.