Read the settings in Web. config
Conn = new SqlConnection (configurationsettings.appsettings["cnfriends.connectstring"]);
<appSettings> <!-- 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 a dataset is used, use the using System. Data.sqlclient
When you configure Web. config, use the using System. Configuration
This reminds me of a freshman when I was studying C language.
BOOL Visible Btnsearch.text = visible? "New Search": "Search";
This one's fine.
dsresult.tables["Users"].rows.count conver.tonint32 (configurationsettings.appsettings["Cokuale.number"]);
Tough enough. 1: Save results and bind with session
session["Search"] = dsresults; Dsresults = (DataSet) session["Search";
Grdresults.databind ();
In fact, the session,application is the object type, so the final is to explicitly convert the type
By the way, determine whether to take the value of the string type as null.
Tough enough. 2: Select rows from the DataTable
datarow[] rows = dsresults.tables["Users"]. Select (filter); Dsresults = Dsresults.clone (); foreach (DataRow row in rows) { dsresults.tables["Tables"]. ImportRow (row); }
Get a control on the WebForm
ImageButton img = (ImageButton) e.item.findcontrol ("Selectbutton")
Jump:
Server.Transfer ("caoxicao.aspx");
Server Control Add JS script (Attributes property)
IMGSHOW.ATTRIBUTES.ADD ("onclick", "document.getElementById (' Tbprefs '). style.display = ' block ';");
Again (Style property),
Img. Style.add ("Cursor", ' Pointer ');
Color Related:
Colorconvert CV = new Colorconvert (); Color selected = Color.Empty; Selected = (olor) CV. ConvertFromString (white);
Add cookies
RESPONSE.COOKIES.ADD (New HttpCookie ("BackColor", R))
My favorite----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); }
New HTML Control Instance
HtmlGenericControl p = new HtmlGenericControl ("P"); P.style.add ("Background-color", BG);
Use this class to represent HTML server control tags that are not directly represented by the. NET Framework classes, such as <span>, <p>, <body>, and <font>
return dataset
public datasets Contact () { String sql = ' @ select * from ... '; DataSet requests = new DataSet (); New Sqldtaadapter (sql,conn). Fill (requests); return requests. GETXML (); Return requests; }
Receive: (When the return value is an XML-formatted dataset)
DataSet results = new DataSet (); Results.readxml (new StringReader (FI). Contactrequest (userid));
When using WebService, simply add the [WebMethod] feature to the Method!
If you add a cache, [WebMethod (cachedurition=600)]
Instantiate WebService
Friendsservice.friendsinfo fi = new Friendsservice.friendsinfo (); String userid; Userid = fi. GetUserID ("...");
Little tips!
HyperLink reg = new HyperLink (); Reg.tooltip = "...";
Check out:
System.Web.Security.Forms.Authentication.SignOut (); Response.Write (Request.applicaltionpath);
Trace Debugging:
Trace.Write Trace.Warn
Abnormal:
1. Throw exception
Program Exception thrown
Throw new ***exception ("...");
2. Catching exceptions
Must start when thrown from a try block, and the try block is used to place all code that might throw an exception.
Eg:
Try { ... } Catch (argumentnullexeption e) { ... }
Unhandled exception Web. config settings
<custom Errors mode = "on" Defaultredriect = "customerror.aspx"; />