51 common codes of Asp.net, asp. net51

Source: Internet
Author: User

51 common codes of Asp.net, asp. net51

1. // the dialog box is displayed. Click to go to the specified page.

2. // pop-up dialog box

3. // delete an object

4. // bind the drop-down list box datalist

5. // display the time in seconds

6. // link to the title

7. // modify the redirection

8. // The OK button is displayed.

9. // format the output data "{0: F2}". The format F2 indicates that there are two digits after the decimal point.

10. // extract dynamic webpage content

11. // get the characters After "."

Copy code

12. open a new window and send parameters: transport parameters:

Receiving parameters:

12. Add dialog box for button

13. Delete selected table records

14. Delete table record warning

15. Click the table row link to another page.

Double-click a table to connect to another page. In the itemDataBind event

Double-click a table to open a new page.

16. Table hyperjoin column Transfer Parameters

17. Click to change the color of the table.

Written in _ ItemDataBound of the DataGrid

18. about Date Format date format setting DataFormatString = "{0: yyyy-MM-dd}" I think e. items. cell ["your column"]. text = DateTime. parse (e. items. cell ["your column"]. text. toString ("yyyy-MM-dd") 19. do not use Response to retrieve error information and go to the specified page. redirect, but use Server. transfer e. g

// Other non-HttpUnhandledException exceptions are handed over to ASP. NET Self-processing will okay :)} Redirect will cause post-back generation and thus loss of error information, so the page orientation should be executed directly on the server side, in this way, you can get the error information on the error handling page and perform corresponding processing 20. clear Cookie

21. Custom Exception Handling

22. horizontal Panel scrolling and vertical auto Scaling

23. Press enter to convert to Tab (1)

(2) // when you press enter on a control with a keydown event, it becomes a tab.

25. The row of the DataGrid changes color with the mouse

26. template Column

Background code

27. number formatting

28. date formatting [aspx page: <% # DataBinder. eval (Container. dataItem, "Company_Ureg_Date") %> displayed as: 19:44:28 I only want: 2004-8-11] <% # DataBinder. eval (Container. dataItem, "Company_Ureg_Date", "{0: yyyy-M-d}") %> how to change it? [Format date], usually object (DateTime) objectFromDB ). toString ("yyyy-MM-dd"); [date validation expression]. correct input format: [], [10:29:39], [] ^ (\ d {2} ([02468] [048]) | ([2, 13579] [26]) [\-\/\ s]? (0? [13578]) | (1 [02]) [\-\/\ s]? (0? [1-9]) | ([1-2] [0-9]) | (3 [01]) | (0? [469]) | (11) [\-\/\ s]? (0? [1-9]) | ([1-2] [0-9]) | (30) | (0? 2 [\-\/\ s]? (0? [1-9]) | ([1-2] [0-9]) | (\ d {2} ([02468] [1235679]) | ([13579] [01345789]) [\-\/\ s]? (0? [13578]) | (1 [02]) [\-\/\ s]? (0? [1-9]) | ([1-2] [0-9]) | (3 [01]) | (0? [469]) | (11) [\-\/\ s]? (0? [1-9]) | ([1-2] [0-9]) | (30) | (0? 2 [\-\/\ s]? (0? [1-9]) | (1 [0-9]) | (2 [0-8]) (\ s (0? [1-9]) | (1 [0-2]) \ :( [0-5] [0-9]) (\ s) | (\ :( [0-5] [0-9]) \ s) ([AM | PM | am | pm] {2, 2 })))? $ B. the following is the correct input format: [0001-12-31], [9999 09 30], [2002/03/03] ^ \ d {4} [\-\/\ s]? (0 [13578]) | (1 [02]) [\-\/\ s]? ([0-2] [0-9]) | (3 [01]) | (0 [469]) | (11 )) [\-\/\ s]? ([0-2] [0-9]) | (30) | (02 [\-\/\ s]? [0-2] [0-9]) $ [case-sensitive conversion] HttpUtility. htmlEncode (string); HttpUtility. htmlDecode (string) 29. how to set the Global variable. add Application [attribute name] = xxx in Application_Start () event in asax, which is your global variable 30. after connecting to the connection generated by HyperLinkColumn, click Connect to open a new window? HyperLinkColumn has a property Target, which can be set to "_ blank. (Target = "_ blank") [ASPNETMENU] Click the menu item to bring up a new window in your menuData. add URLTarget = "_ blank" to the menu item of the xml file, for example:

Upgrade your aspnetmenu to version 1.2. Read the TextBox value of the DataGrid Control.

33. three template columns in the DataGrid contain Textbox columns DG_ShuLiang (Quantity) DG_DanJian (unit price) DG_JinE (amount) in 5.6.7, respectively, it is required that the amount be calculated automatically when the quantity and unit price are entered: quantity * unit price = amount, and the input time limit must be numeric. how can I use a client script to implement this function?

34. Why do I always refresh the lower row selected by the datagrid and scroll to the top? The selected row cannot be seen due to the relationship between the screen. Page_load page. smartNavigation = true 35. Modify the data in the Datagrid. When you click the edit key, the data appears in the text box. How can I control the size of the text box?

36.Dialog Box

Copy code

(StrScript);} 37.Format the time:String aa = DateTime. Now. ToString ("yyyyYearMMMonthDdDay"); 1.1Returns the current year, month, day, hour, minute, and second.CurrentTime = System. DateTime. Now; 1.2Returns the current year.IntYear= DateTime. Now. Year; 1.3Returns the current month.IntMonth= DateTime. Now. Month; 1.4Current dayIntDay= DateTime. Now. Day; 1.5Current TimeIntHour= DateTime. Now. Hour; 1.6Returns the current score.IntMinute= DateTime. Now. Minute; 1.7Current secondIntSeconds= DateTime. Now. Second; 1.8Current millisecondIntMillisecond= DateTime. Now. Millisecond; 38. Custom paging code: first define the variable :

39.DataGridUsage: Confirm deletion:

Style alternation:

Add an ID column:

ClickDataGrid1Delete all displayed data

40. When the file is in different directories, you need to obtain the database connection string (if the connection string is placed inWeb. configAnd thenGlobal. asax) InApplication_StartAdd the following code:

3 41. Variable. ToString ()Character type conversion Convert to string

42, Variable. Substring (Parameters1,Parameters2 );Truncates a part of a string.1It is the start number of digits on the left.2To intercept a few digits. For example:String s1 = str. Substring (0, 2); 43. Log on to another website on your website:(If your page is nested, because one page can only have oneFORMIn this case, you can go to another page and then submit the login information)

The text box name must be the name on the Web page you want to log on.VsnifferLook. The following code obtains the login information entered by the user:

44. datagridIf the index is exceeded during deletion

45.Warning window/** // <Summary> ///Server pop-upAlertDialog Box/// </Summary> /// <param name = "str_Message">Prompt information,Example:"Cannot be blank! "</Param> // <param name =" page "> PageClass</Param> public void Alert (string str_Message, Page page) {page. registerStartupScript ("", "<script> alert ('" + str_Message + "'); </script>") ;}36.Reload this warning window,Focus a widget

47.Confirmation dialog box

48.Reload confirmation dialog box, click OK to trigger a hidden button event, and click Cancel to trigger a hidden button event

49.Focus

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.