Home > Backend Development > C#.Net Tutorial > Introduction to C# Web Applications Classic Notes (Volume 2)

Introduction to C# Web Applications Classic Notes (Volume 2)

Y2J
Release: 2017-04-26 10:49:35
Original
2043 people have browsed it

Read the settings in Web.config

Conn = new SqlConnection(ConfigurationSettings.AppSettings[“cnFriends.ConnectString”]);
Copy after login
 <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>
Copy after login

Several namespaces

When using DataSet, use using system.Data.SqlClient

When When configuring Web.config, use using system.Configuration

This reminds me of when I was learning C language in my freshman year

bool visible 
btnSearch.Text = visible? “New Search” : “Search” ;
Copy after login

This is also pretty good

dsResult.tables[“Users”].rows.count 
Conver.Tonint32(ConfigurationSettings.AppSettings[“Cokuale.number”]);
Copy after login

Ruthless 1: Use Session to save the results and bind them

Session[“Search”] = dsResults; 
dsResults = (DataSet) Session[“Search”];
Copy after login

grdResults.DataBind();
In fact, Session, Application, etc. are stored in object type, so they must be displayed in the end. Type conversion type
By the way, use null to judge whether a string type value is obtained.

Quehen 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); 
}
Copy after login

Get a control on the webForm

ImageButton img = (ImageButton)e.Item.FindControl(“Selectbutton”)
Copy after login

Jump:

Server.Transfer(“Caoxicao.aspx”);
Copy after login

Add js script (Attributes attribute) to the server control

imgShow.Attributes.Add(“onclick”,”document.getElementById(‘tbPrefs&#39;).style.display = ‘block&#39;;”);
Copy after login

Then (Style attribute),

img.Style.Add(“Cursor”,&#39;Pointer&#39;);
Copy after login

Color related:

ColorConvert cv = new ColorConvert(); 
Color selected = Color.Empty; 
Selected = (olor)cv.ConvertFromString(White);
Copy after login

Add Cookie

Response.Cookies.Add(new HttpCookie(“backColor”,r))
Copy after login

My Favorite----User Control

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); 
}
Copy after login

New Html Control Instance

HtmlGenericControl p = new HtmlGenericControl(“p”); 
p.Style.Add(“background-color”,bg);
Copy after login

Use this Classes can represent HTML server control tags that are not directly represented by .NET Framework classes, such as ,

, and

Return DataSet

Public DataSet Contact() 
{ 
         String sql = “@ Select * from … …”; 
         DataSet requests = new DataSet(); 
         New SqlDtaAdapter (sql,conn).Fill(requests); 
         //return requests.GetXml(); 
                   Return requests; 
}
Copy after login

Receive: (when the return value is a data set in Xml format)

DataSet results = new DataSet(); 
Results.ReadXml(new StringReader(fi.ContactRequest(userid)));
Copy after login

When using WebService, just add the [WebMethod] attribute to the method!

If you add cache, then [WebMethod(CacheDurition=600)]

Instantiate WebService

FriendsService.FriendsInfo fi = new FriendsService.FriendsInfo(); 
String userid; 
Userid = fi.GetUserID(“…”);
Copy after login

Tips!

HyperLink reg = new HyperLink(); 
Reg.ToolTip = “… …”;
Copy after login

Checkout:

System.Web.Security.Forms.Authentication.SignOut(); 
Response.write (Request.ApplicaltionPath);
Copy after login

Trace debugging:

Trace.Write 
Trace.Warn
Copy after login

Exception:

1. Throws exception

Program exception throws

Throw new ***Exception(“…”);

2. Catch exceptions

It must be thrown from a try code block at the beginning. The try code block is used to place all codes that may throw exceptions.

Eg:

Try 
                  { 
                            … … 
                  } 
         Catch(ArgumentNullExeption e) 
                  { 
                            … 
                  }
Copy after login

Unhandled exception web.config setting

<Custom Errors mode = “on” defaultRedriect = “customerror.aspx”; />
Copy after login

The above is the detailed content of Introduction to C# Web Applications Classic Notes (Volume 2). For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template