My Development Notes

By Haemoglobin
3/10/2010 (revision 3)

Controls

ControlDescription
ButtonCan either use the Click event, or can wire multiple buttons to the same event handler and switch logic based on the CommandName property.
protected void Playback_Command(object sender, CommandEventArgs e) {
    switch (e.CommandName) {
        case "Previous": 
            break; 
        case "Next":
            break; 
    }
}
Set the CausesValidation property to false if you wish to bypass validation on the page. Such as for a reset button.
Literal Set the Mode property to Encode, PassThrough or Transform
ImageMap
protected void Page_Load(object sender, EventArgs e) {
    ImageMap imageMap = new ImageMap(); 
    imageMap.ImageUrl = "images/image.jpg"; 
    imageMap.HotSpotMode = HotSpotMode.PostBack; 
    Controls.Add(imageMap); 

    RectangleHotSpot hotspot = new RectangleHotSpot(); 
    hotspot.Top, .Bottom, .Left, .Right = 
    hotspot.PostBackValue = "Area 1"; 
    imageMap.HotSpots.Add(hotspot); 
}

protected void ImageMapStopLight_Click(object sender, ImageMapEventArgs e) {
    e.PostBackValue; 
}
Calendar
protected void Calendar_DayRender(object sender, DayRenderEventArgs e) {
    if(e.Day.Date == DateTime.Now()) {
        e.Cell.Controls.Add(new Literal("Today")); 
    }
}
FileUpload
protected void Button_Click(object sender, DayRenderEventArgs e) {
    if(FileUpload1.HasFile) {
        FileUpload1.FileBytes.Length
        FileUpload1.FileName
        FileUpload1.PostedFile.ContentType
        FileUpload1.SaveAs(MapPath("~/Uploads/" + FileUpload1.FileName); 
    }
}
Panel Properties: BackImageUrl, DefaultButton, Direction, ScrollBars, Wrap
MultiView/View The MultiView control contains multiple View Controls.
Can be used for a multistep registration process for example.
Properties: ActiveViewIndex Set in Next/Prev button click for example.
Wizard Builds on top of the MultiView control and automatically displays Next/Previous/Finish buttons if Wizard1.StepType = WizardStepType.Auto (default)
Xml
Xml1.DocumentSource = "App_Data/Data.xml"; 
Xml1.TransformSource = "App_Data/DataTransform.xsl"; 

Data Source and Data Bound Controls

ObjectDataSource

public class Customers {
    public static IEnumerable|IListSource|IDataSource|IHierarchicalDatasource GetCustomers() { .. }
}


<asp:ObjectDataSource ID="ObjectDataSource1" runat="server" TypeName="Customers" SelectMethod="GetCustomers" [SortParameterName="sortCol" StartRowIndexParameterName="pageStart" MaximumRowsParameterName="numRecords"]
[EnableCaching="true" CacheDuration="30"]/> 
//If SelectMethod has parameters embed the following in ObjectDataSource
<SelectParameters>
    <asp:QueryStringParameter> Name="customerId" QueryStringField="custId" Type="string"/> 

</SelectParameters>  

//InsertMethod, UpdateMethod, DeleteMethod defined in the same way.
//FilterExpression="param='{0}' combined with FilterParameters (filtered after the database call)

<asp:DetailsView ID="DetailsView1" runat="server" DataSourceID="ObjectDataSource1" AllowPaging="true" PageSize="10" AllowSorting="true"
AutoGenerateRows = "false"> 
<Fields> 
<asp:BoundField> DataField="CustomerID" ReadOnly="true" InsertVisible="false"/> 
...
</Fields> 
</asp:DetailsView> 

SqlDataSource

<asp:SqlDataSource ID="SqlDataSource1" ConnectionString="<%$ ConnectionStrings:MyConnectionString %>" 
SelectCommandType="Text" SelectCommand="SELECT * FROM Customers WHERE Group=@Group" DataSourceMode="DataReader"/> 
//Use SelectParameters similar to ObjectDataSource for mapping to @Group parameter

XmlDataSource

<asp:XmlDataSource ID="XmlDataSource1" DataFile="~/App_Data/products.xml" TransformFile="~/App_Data/ProductTransform.xsl" XPath="/Products/Product[Category='Category: Beverages']" /> 
//Contains no functionality for insert / delete / update

LinqDataSource

<asp:LinqDataSource ID="LinqDataSource1" ContextTypeName="NorthwindDataContext" EnableInsert="true" EnableUpdate="true" OrderBy="CompanyName" TableName="Suppliers" Where="Country== @Country"> 
<WhereParameters> 
<asp:QueryStringParameter> ....
</WhereParameters> 
</asp:LinqDataSource> 

Data Bound Controls

  • ListBox
  • DropDownListBox
  • ListBox
  • CheckBoxList
  • RadioButtonList
  • BulletedList

The above have DataSourceID, DataTextField, DataValueField properties.

GridView

 [AllowPaging]
 [AllowSorting]
 [AutoGenerateColumns]
 [DataKeyNames="columnName"]
 [DataSourceID]
 Columns
    asp:CommandField [ShowDeleteButton] [ShowEditButton] [ShowSelectButton]
    asp:BoundField [DataField] [HeaderText] [ReadOnly] [SortExpression="columnName"]
    asp:CheckBoxField [DataField] [HeaderText] [ReadOnly] [SortExpression="columnName"]

Text='<%# Bind("ProductName") %>>' //two way databinding for GridView, DetailsView, FormView otherwise use Eval

DetailsView

Same as GridView except define Fields instead of Columns. Automatically renders one item at a time.

FormView

Need to define ItemTemplate has AllowPaging attribute.

Repeater

Need to define ItemTemplate displays all records.

Text='<%# Eval("ProductName") %>>' //for controls in ItemTemplate to bind to data source.

ListView

Need to define LayoutTemplate which then contains a div with ID itemPlaceholder for the ItemTemplate.

DataList

Like the repeater control but also has RepeatLayout and RepeatDirection properties.

TreeView

Need to bind to a IHierarchicalDataSource such as XmlDataSource.

DataBindings
    asp:TreeNodeBinding DataMember="Customer" TextField="Name" ValueField="CustomerId"
    asp:TreeNodeBinding DataMember="Order" TextField="ShipDate" ValueField="OrderId"

Web Parts

WebPartManagerRequired on every page that includes web parts.
WebPartBase class for all web parts. Provies UI, personalization and connection features.
CatalogPartUI for managing a group of web parts that can be added to the page.
PageCatalogPartSame as CatalogPart but specific to a particular page.
EditorPartUser defined customizations for the web part, modification of property settings.
DeclarativeCatalogPartAllows you to declare web parts that are available to add to a page or site.
WebPartZoneDefines area that web parts can be hosted.
EditorZoneProvies area where EditorPart controls can exist.
CatalogZoneDefines area on the page wehre CatalogPart controls can exist.

Comments

Powered by BlogEngine.NET 1.6.1.0 | Design by styleshout | Enhanced by GravityCube.net | 1.4.5 Changes by zembian.com | Adapted by HamishGraham.NET
(c) 2010 Hamish Graham. Banner Image (c) Chris Gin