Read settings in Web. config
Conn = new sqlconnection (configurationsettings. etettings ["cnfriends. connectstring"]);
<Deleetask>
<! -- User application and configured property settings go here. -->
<! -- Example: <add key = "settingname" value = "settingvalue"/> -->
<Add key = "cnfriends. connectionstring" value = "Data Source = (local) \ netsdk; initial catalog = friendsdata; user id = sa"/> </appsettings>
Several namespaces
When dataset is used, using system. Data. sqlclient is used.
When configuring web. config, use using system. Configuration
This reminds me of the C language I learned in my freshman year.
Bool visible
Btnsearch. Text = visible? "New search": "Search ";
This is pretty good.
Dsresult. Tables ["users"]. Rows. Count
Conver. tonint32 (configurationsettings. receivettings ["cokuale. Number"]);
1: Use session to save the result and bind it
Session ["Search"] = dsresults;
Dsresults = (Dataset) session ["Search"];
Grdresults. databind ();
In fact, sessions and applications store the object type. Therefore, the type must be explicitly converted.
By the way, null is used to determine whether a value of the string type is obtained.
Hard enough 2: Select rows from datatable
Datarow [] rows = dsresults. Tables ["users"]. Select (filter );
Dsresults = dsresults. Clone ();
Foreach (datarow row in rows)
{
Dsresults. Tables ["tables"]. importrow (ROW );
}
Obtain a control on webform.
Imagebutton IMG = (imagebutton) E. Item. findcontrol ("selectbutton ")
Jump:
Server. Transfer ("caoxicao. aspx ");
Add a JS script (attributes attribute) to the server control)
Imgshow. Attributes. Add ("onclick", "document. getelementbyid ('tbprefs'). style. Display = 'block ';");
(Style attribute ),
IMG. style. Add ("cursor", 'pointer ');
Color:
Colorconvert CV = new colorconvert ();
Color selected = color. empty;
Selected = (olor) cv. convertfromstring (white );
Add cookie
Response. Cookies. Add (New httpcookie ("backcolor", R ))
My favorites-User Controls
Using friendsreunion. controls;
Protectd override void oninit (eventargs E)
{
Friendsfooter _ footer = (friendsfooter) loadcontrol (request. applicationpath + "/controls/friendsfooter. aspx ");
Subheader _ Subheader = new Subheader ();
}
Page. contros. addat (0, _ footer );
Page. contros. addat (0, _ Subheader );
Base. oninit (E );
}
Create an HTML control instance
Htmlgenericcontrol DIV = new htmlgenericcontrol ("Div ");
Div. style. Add ("Background-color", BG );
This class can be used to mark HTML server controls that are not directly represented by the. NET Framework class, such as <span>, <div>, <body>, and <font>
Return Dataset
Public dataset contact ()
{
String SQL = "@ select * from... ...";
Dataset requests = new dataset ();
New sqldtaadapter (SQL, Conn). Fill (requests );
// Return requests. getxml ();
Return requests;
}
Receiving: (when the returned value is a dataset in XML format)
Dataset Results = new dataset ();
Results. readxml (New stringreader (Fi. contactrequest (userid )));
When using WebService, you only need to add the [webmethod] feature to the method!
If a cache is added, [webmethod (cachedurition = 600)]
Instantiate WebService
Friendsservice. friendsinfo Fi = new friendsservice. friendsinfo ();
String userid;
Userid = Fi. getuserid ("…");
Small tips!
Hyperlink Reg = new hyperlink ();
Reg. tooltip = "… ...";
Check out:
System. Web. Security. Forms. Authentication. signout ();
Response. Write (request. applicaltionpath );
Tracking debugging:
Trace. Write
Trace. Warn
Exception:
1. Throw an exception
ProgramException thrown
Throw new *** exception ("…");
2. Capture exceptions
Must start with a tryCodeThe try code block is used to place all codes that may throw exceptions.
Eg:
Try
{
... ...
}
Catch (argumentnullexeption E)
{
...
}
Unhandled exceptions web. config settings
<Custom errors mode = "on" defaultredriect = "customerror. aspx";/>