C # getting started with Web Applications

Source: Internet
Author: User

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";/>

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.