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

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

Apr 26, 2017 am 10:49 AM

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!

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

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Best Graphic Settings
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. How to Fix Audio if You Can't Hear Anyone
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
WWE 2K25: How To Unlock Everything In MyRise
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

How to delete Xiaohongshu notes How to delete Xiaohongshu notes Mar 21, 2024 pm 08:12 PM

How to delete Xiaohongshu notes? Notes can be edited in the Xiaohongshu APP. Most users don’t know how to delete Xiaohongshu notes. Next, the editor brings users pictures and texts on how to delete Xiaohongshu notes. Tutorial, interested users come and take a look! Xiaohongshu usage tutorial How to delete Xiaohongshu notes 1. First open the Xiaohongshu APP and enter the main page, select [Me] in the lower right corner to enter the special area; 2. Then in the My area, click on the note page shown in the picture below , select the note you want to delete; 3. Enter the note page, click [three dots] in the upper right corner; 4. Finally, the function bar will expand at the bottom, click [Delete] to complete.

Can deleted notes on Xiaohongshu be recovered? Can deleted notes on Xiaohongshu be recovered? Oct 31, 2023 pm 05:36 PM

Notes deleted from Xiaohongshu cannot be recovered. As a knowledge sharing and shopping platform, Xiaohongshu provides users with the function of recording notes and collecting useful information. According to Xiaohongshu’s official statement, deleted notes cannot be recovered. The Xiaohongshu platform does not provide a dedicated note recovery function. This means that once a note is deleted in Xiaohongshu, whether it is accidentally deleted or for other reasons, it is generally impossible to retrieve the deleted content from the platform. If you encounter special circumstances, you can try to contact Xiaohongshu’s customer service team to see if they can help solve the problem.

What should I do if the notes I posted on Xiaohongshu are missing? What's the reason why the notes it just sent can't be found? What should I do if the notes I posted on Xiaohongshu are missing? What's the reason why the notes it just sent can't be found? Mar 21, 2024 pm 09:30 PM

As a Xiaohongshu user, we have all encountered the situation where published notes suddenly disappeared, which is undoubtedly confusing and worrying. In this case, what should we do? This article will focus on the topic of &quot;What to do if the notes published by Xiaohongshu are missing&quot; and give you a detailed answer. 1. What should I do if the notes published by Xiaohongshu are missing? First, don't panic. If you find that your notes are missing, staying calm is key and don't panic. This may be caused by platform system failure or operational errors. Checking release records is easy. Just open the Xiaohongshu App and click &quot;Me&quot; → &quot;Publish&quot; → &quot;All Publications&quot; to view your own publishing records. Here you can easily find previously published notes. 3.Repost. If found

How to connect Apple Notes on iPhone in the latest iOS 17 system How to connect Apple Notes on iPhone in the latest iOS 17 system Sep 22, 2023 pm 05:01 PM

Link AppleNotes on iPhone using the Add Link feature. Notes: You can only create links between Apple Notes on iPhone if you have iOS17 installed. Open the Notes app on your iPhone. Now, open the note where you want to add the link. You can also choose to create a new note. Click anywhere on the screen. This will show you a menu. Click the arrow on the right to see the "Add link" option. click it. Now you can type the name of the note or the web page URL. Then, click Done in the upper right corner and the added link will appear in the note. If you want to add a link to a word, just double-click the word to select it, select "Add Link" and press

How to add product links in notes in Xiaohongshu Tutorial on adding product links in notes in Xiaohongshu How to add product links in notes in Xiaohongshu Tutorial on adding product links in notes in Xiaohongshu Mar 12, 2024 am 10:40 AM

How to add product links in notes in Xiaohongshu? In the Xiaohongshu app, users can not only browse various contents but also shop, so there is a lot of content about shopping recommendations and good product sharing in this app. If If you are an expert on this app, you can also share some shopping experiences, find merchants for cooperation, add links in notes, etc. Many people are willing to use this app for shopping, because it is not only convenient, but also has many Experts will make some recommendations. You can browse interesting content and see if there are any clothing products that suit you. Let’s take a look at how to add product links to notes! How to add product links to Xiaohongshu Notes Open the app on the desktop of your mobile phone. Click on the app homepage

How to publish notes tutorial on Xiaohongshu? Can it block people by posting notes? How to publish notes tutorial on Xiaohongshu? Can it block people by posting notes? Mar 25, 2024 pm 03:20 PM

As a lifestyle sharing platform, Xiaohongshu covers notes in various fields such as food, travel, and beauty. Many users want to share their notes on Xiaohongshu but don’t know how to do it. In this article, we will detail the process of posting notes on Xiaohongshu and explore how to block specific users on the platform. 1. How to publish notes tutorial on Xiaohongshu? 1. Register and log in: First, you need to download the Xiaohongshu APP on your mobile phone and complete the registration and login. It is very important to complete your personal information in the personal center. By uploading your avatar, filling in your nickname and personal introduction, you can make it easier for other users to understand your information, and also help them pay better attention to your notes. 3. Select the publishing channel: At the bottom of the homepage, click the &quot;Send Notes&quot; button and select the channel you want to publish.

Scan printed and handwritten notes in the Notes app for iPhone Scan printed and handwritten notes in the Notes app for iPhone Nov 29, 2023 pm 11:19 PM

In 2022, Apple added a new feature to the Notes app on iPhone and iPad that allows you to quickly scan printed or handwritten text and save it in a digital text format. Read on to learn how it works. On earlier versions of iOS and iPadOS, scanning text into Apple's Notes app required tapping the note's text field and then tapping the "Live Text" option in the pop-up menu. However, Apple is making it easier to digitize real-world notes in 2022. The following steps show you how to do this on a device running iOS 15.4 or iPadOS 15.4 and above. On your iPhone or iPad, open "

How to recover deleted notes on iPhone How to recover deleted notes on iPhone Jul 14, 2023 pm 07:25 PM

Most people write down everything, including recipes, birthdays, song lyrics, and more. on their iPhone’s Notes app. But many iPhone users reported that they deleted very important notes on their iPhone by mistake and now they are very nervous and frustrated. They don't know how to restore it on iPhone. We have done a lot of research on the matter and found two methods to recover deleted notes from iPhone. In this article, we will explain these two methods with which you can easily get back deleted notes. How to Recover Deleted Notes via Notes App Step 1: You should first launch the Notes app from the home screen on your iPhone. Step 2: Launch the Notes application

See all articles