.NET basics Flashcards
Common Language Runtime (CLR)
The engine that executes all .NET programs
Common Intermediate Language (CIL)
The language used by the CLR
C# strings and escaped characters
- " (double quote)
- \n (new line)
- \t (horizontal tab)
- \ (backward slash)
Arrays
- string []
- int []
- int [,] (two-dimensional int array)
ArrayList
- Dynamic collection that supports any type of object and allows resizing
- Example:
- ArrayList x = new ArrayList();
Delegates
Can be used as variables to point at methods that accept the same parameters
script runat = “server”
Sets the code to run on the web server, rather than in the user’s web browser
Generics
A class that supports any type of variables or objects
Try parse
- Returns a boolean representing the success or failure of the parse method
- Example:
- bool success = Decimal.TryParse(X.Value, out XX)
if (IsPostBack == false)
Postback verifies that the page is being loaded for the first time. It is used in order to initialize content only on the first load
ListItem Class
- Attributes - Gets a collection of attribute name and value pairs for the ListItem that are not directly supported by the class
- Enabled - Gets or sets a value indicating whether the list item is enabled
- Selected - Gets or sets a value indicating whether the item is selected
- Text - Gets or sets the text displayed in a list control for the item represented by the ListItem
- Value - Gets or sets the value associated with the ListItem
HtmlSelect Class
- Value - Gets the value of the selected item in the HtmlSelect control or sets the SelectedIndex property of the control to the index of the first item in the list with the specified value
- SelectedIndex - Gets or sets the ordinal index of the selected item in an HtmlSelect control
- InnerText - Gets or sets the content between the opening and closing tags of the control with automatic conversion of special characters to their equivalent HTML entities. This property is not supported for this control.(Overrides HtmlContainerControl.InnerText)
Apply a CSS style to an HTML control
ControlName.Style[“AttributeName”] = “AttributeValue”
- InnerHtml
- InnerText
- The HTML content in the control
- The text equivalent of the HTML content in the control
Server.HtmlEncode
Property allowing to display an HTML element as a text element
debug = true
Should be turned off when deployed to a server because it will slow down the application
Units
- Unit.Pixel ()
- Unit.Percentage ()
Color
- ForeColor = Color.FromArgb()
- ForeColor = Color. Crimson
- ForeColor = ColorTranslator.FromHtml()
Padding
padding: top right bottom left;
Create tables
- // Create a new TableRow object.
- TableRow rowNew = new TableRow();
- // Put the TableRow in the Table.
- tbl.Controls.Add(rowNew);
HTML postback events
- HtmlButton.ServerClick Event
- HtmlSelect.ServerChange Event
Web control events
- Click
- TextChanged
- CheckedChanged
- SelectedIndexChanged
Autopostback
- Postback is done automatically as soon as the control is change
- Example:
- CheckBox id=”” runat=”server” AutoPostBack=”True” OnCheckedChanged=”Check_Clicked”
_doPostBack
A Javascript function that is generated automatically when at least one control uses automatic postback. Sends the eventTarget and eventArgument to the server
Find the control ID of the sender
string ctrlName = ((Control)sender).ID
- Page Load
- Page Prerender
- Page Load : Perform actions common to all requests, such as setting up a database query. At this point, server controls in the tree are created and initialized, the state is restored, and form controls reflect client-side data
- Prerender :Perform any updates before the output is rendered. Any changes made to the state of the control in the prerender phase can be saved, while changes made in the rendering phase are lost
Get an enumeration of know colors
- string[] colorArray = Enum.GetNames(typeof(KnownColor));
- lstBackColor.DataSource = colorArray;
- lstBackColor.DataBind();
Base ()
- The base keyword is used to access members of the base class from within a derived class
- Example:
- public class DerivedClass : BaseClass
- {
- public DerivedClass() : base() { }
- }
- public class DerivedClass : BaseClass
Retaining member variables
Make a copy of them in the ViewState[“variableName”] during PreRender
Placing an object in the view state
Add the keyword [serializable] before the class name
Page.PreviousPage property
- Is used to retrieve information from the previous page
- Example:
-
CrossPage prevPage = PreviousPage as CrossPage;
- if (prevPage != null)
- {
-
lblInfo.Text += “You typed in this: “ + prevPage.FullName + “
“;
-
lblInfo.Text += “You typed in this: “ + prevPage.FullName + “
- }
-
CrossPage prevPage = PreviousPage as CrossPage;
Url encoding
- UrlEncode()
- UrlDecode()
- HttpServerUtility class & Page.Server Property
Request.QueryString
- The QueryString collection retrieves the values of the variables in the HTTP query string
- Syntax:
- Request.QueryString(variable)[(index)|.Count]
Cookie Class (System.Net collection)
- Example:
- HttpCookie cookie = new HttpCookie(“preferences”)
- Response.Cookies.Add(cookie)