Problem sharing in C # development

Source: Internet
Author: User
Tags rtrim
1. Constructors cannot take a return value type because the constructor returns the object itself.

2. Convert the string to a date type, using Datetime.parese () or DateTime. The ParseExact () function.

3, if (! Page.IsPostBack) {}

Use this function to make a Web page run the contents of the function body only at the first load, and in the Page_Load () event, it is usually used for initialization. If you do not use this function, you may run the contents of the if () function body again when some controls return, causing the modified values of the related controls to not be applied correctly.

4. The GridView field (BoundField) has an attribute HTMLEncode. This property is used to wrap the HTML, and if True (the default), the contents of the field are displayed as-is. If False, the corresponding HTML tag in the field is rendered. Therefore, to make the picture link in the field appear, set htmlencode= "true".

5. How to format the page after getting the date: Eval ("Wtdate", "{0:YYYY-MM-DD}")

However, the string formatting in DateTime.Now.Date.ToString ("Yyyy-mm-dd") is different.

6, the nvarchar data type, in SQL SERVER 2005 has the nvarchar (max) type to represent the maximum number of 2^32, but the type is not supported in. net2.0, and the maximum number of nvarchar can still be represented as 4000 bytes.

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

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

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

8, it is best to store values for each field, even if not used, the initial setting, in order to avoid null values, there is a data type mismatch, such as the Datetime,uniqueidentifier field, remove null value for processing will cause trouble.

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

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

10, stored procedures, wildcard characters and parameters used in combination, to use the string addition, not directly on the side of the parameters, as follows:

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

11. To get the value of an item in an List<t> object, use the following method:

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

Assuming that 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 (such as), there may be errors due to security issues: Description: The request validation process detected a potentially dangerous client input value and the processing of the request has been aborted. This value may indicate an attempt to compromise the 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 inputs.

13, display the contents 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 can easily display the login status and provide a shortcut link for login and logout. However, sometimes it is inconvenient, especially when you want to exit the frames page when you log out, and you are unable to use the control. You can directly use the LinkButton control, in the Click event, add the following two sentences, you can implement logout and jump to the parent window of the frames page:

FormsAuthentication.SignOut ();

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

15. Close the window in C #:
Response.Write ("<script language:javascript>javascript:window.close ();</script>");

Related Article

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.