Professional ASP.NET 4.5 in C# and vb.net (2)

Chapter 5: Web Server Controls
Label control’s Hot key ==> AccessKey=”N” AssociatedControlID=”TextBox1”
image
Literal Control ==> Mode=”Encode”, will encode the output before displaying
image
To enable AutoPostback, enable the property for that control (drop down list, textbox tec.)
image
Button server Control:
CauseValidation Property:
CommandName Property:
You can have two buttons that has the same OnCommand method, but different name, such as
image
In the OnCommand code, you can check the command name to decide what code to run:
image
If you have other parameters to add to the button, use CommandArgument property. in the code behind, you check the value of e.CommandArgument.
Button event:
image
Page 199
Chapter 6: Validation server Controls
To use unobstrusive validation, need jQuery; also, configure, either
(1) web.config
image
(2) or, in global.asax
image

Note: The data-* attributes are only rendered when unobstrusive validation is turned one.
When using requiredfieldvalidator to validate a drop down, the the InitialValue to the first value (default selected) of the drop down, such as this one:
image
Use CompareValidator to ensure the input is an integer.
image
You can use “Currency”,”Date”, “Double”, “Integer”, String”
Use CompareValidator to validate against a value
input has to be an integer >= 18
image
RangeValidator
Must be an integer between 30 and 40
image
To turn off client-side validation, set the validation control’s property EnableClientScript to false.
if you want to show images (instead of text) as error message, you can edit the Text property as this one shows:
image
You get this:
image
Validation Groups
Use Validation Groups to validate different groups of controls on the same form
image
Chapter 7: User and Server Controls
Load user control into form programmatically
image
To access properties and methods that the user control exposes, you need to cast the control from the generic control type to its actual type.
image
page 240

Custom Server Control – Creating a test one!!
User Control is a great way of encapsulating functionality in one unit.
The custom control needs to be created as a new project, not a new item.
image
Create a ASP.NET Server Control project, compile it, and add another web project, compile the solution, so you have:
image
After that you should see your server control in the toolbox:
image
If you don’t, right click the white space in toolbox, and check “Show All”, you should see a lot more controls in the toolbox, including your custom one. uncheck the “Show All”, and most will be gone, but your custom control will stay. Now you can drag your custom control to your web form.
Page 299

Chapter 8: Data Binding
Once you set up a data source, you can configure the data source mode to either DataSet or DataReader
image
Conflict Detection
Default is OverwriteChanges – If changed to CompareAllValues: does not update the data if something has changed since the data is retrieved for update.
image
To detect and process data access error: In DataSource’s Updated event.
image
To use Entity Data Source
(1) Add a Entity Data Model toy our project, configure it to map to tables/store procs/views of a database.
image
(2) Add a Entity Data Source and use that connection as a connection, and configure it.
image
image
Query Extender – works with any data source control that implements the iQueryableDataSource interface. That includes LinqDataSource and EntityDataSource.
(1) Drag it to the designer
image
(2) Use the EntityDataSource’s id as the “TargetControlID” of the QueryExtender.
image
he Query Extender further filter the query results to the condition specified
image

XMLDataSource Control: Binding XML in memory or on a physical drive.
ObjectDatSource – bind directly to middle-layer classes or business objects.
Enabling caching by changing the property in the data source. Note that SQLDataSource caching is available only when the DatsSourceMode is DataSet.
A good control that can be used: Chart
image
image
Chapter 9: Model Binding
MVC was only available in MVC, but now also available in Web Form.
In GridView, you specify the optional ItemType=”Customer”, to get the intellisense.
If you’re expecting a parameter from the QueryString:
image
System.Web.ModelBinding.QueryString is a ValueProvider
ValueProvider:
Form, Control, QueryString, Cookie, Profile, RouteData, Session
Example: A drop down and a GridView
image
The GridView is to be refreshed upon selection of an item in Drop Down: (Drop down’s AutoPostBack is true, so GridView will refreshed during the postback)
image
Inserting
image
image

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s