打印本文 打印本文 关闭窗口 关闭窗口
ASP.NET 从Beta1 升级到 Beta2 的新变化
作者:武汉SEO闵涛  文章来源:敏韬网  点击数3489  更新时间:2009/4/23 10:48:41  文章录入:mintao  责任编辑:mintao

ASP.NET 从Beta1 升级到 Beta2 的新变化

         In config.web “debugmode” has been renamed to “debug”.

         RegisterPostBackScript() has been removed from Control. You no longer need to call RegisterPostBackScript() if you are using GetPostBackEventReference(). Calls to RegisterPostBackScript() should be removed from code.

         Regex options have been modified to use an enumeration instead of string values. For cross-.net framework consistency, regular expressions options should be an enumeration type, rather than a string value. The enumeration is in System.Text.RegularExpressions.RegexOptions. The string constructor has been marked as deprecated. This constructor has been retained since the JScript compiler relies on it. The mapping of strings to enumerated types is as follows.

String RegexOptions Enum "" None c Compiled d Debug (emits console text in debug builds) i IgnoreCase m Multiline n ExplicitCapture r RightToLeft s Singleline x IgnorePatternWhitespace

The following examples show the differences between the old and new forms.

// use a case-insensitive regex (old form)

Regex r = new Regex("mypatt", "i")

// use a case-insensitive regex (new form)

Regex r = new Regex("mypatt", RegexOptions.IgnoreCase)

// use a compiled regex, case-insensitive regex (old form)

Regex r = new Regex("mypatt", "ic")

// use a compiled regex, case-insensitive regex (new form)

Regex r = new Regex("mypatt", RegexOptions.IgnoreCase|RegexOptions.Compiled)

         The ASP.NET persistence format was changed. The name of the property becomes the tag name, and the attributes that were on the (redundant) child tag move to the tag itself. For collections and templates the property name becomes the tag name.

         The IDesignerAccessor interface has been deleted; any design-time functionality a control offers should be implemented in the associated designer.

         The IParserAccessor interface is now privately implemented. Only the parser should have been calling AddParsedSubObject(). If you override AddParsedSubObject() in your control, the access level has changed to protected.

         The IAttributeAccessor interface is also privately implemented.

Old Code:

Control.GetAttribute("Attrib")     
Control.SetAttribute("Attrib", "Value")

New Code:

Control.Attributes["Attrib"] = Value

         Changes were made in the ASP.NET Control designer framework. All public methods and properties using IHTMLElement and other trident interfaces are no longer public. Control designers no longer implement IOleCommandTarget. The Web forms designer handles IOleCommandTarget internally. Designers return a collection of DesignerVerb objects. The behavior implementations DHTMLBehavior and IdentityBehavior cannot be accessed directly. Use the IHtmlControlDesignerBehavior and IUserControlDesignerBehavior interfaces to access them from your designer.

Old form New form TemplatedControlDesigner::CanTemplateEdit CanEnterTemplateMode TemplatedControlDesigner::TemplateMode InTemplateMode HtmlControlDesigner::HTMLElement DesignTimeElement UserControlDesigner::ViewLinkRootElement DesignTimeElementView

         System.Web.UI.Web controls.Design.WebControlToolboxItem has been moved to System.Web.UI.Design.WebControlToolboxItem. This only affects you if you have metadata on your common language runtime controls that derive from Control directly (rather than from WebControl).

         The BubbleEvent() and InvokeBubbleEvent() methods on Control have been renamed to OnBubbleEvent() and RaiseBubbleEvent(), respectively.

         The paging semantics of the DataGrid control have changed. In Beta1, DataGrid paging worked such that the user''''s PageIndexChanged event handler was responsible for calling DataBind(), and the DataGrid would automatically update the CurrentPageIndex property of the DataGrid. This did not make the requirement to implement an event handler intuitive. Therefore, in Beta2, the DataGrid will not change the CurrentPageIndex automatically. In your event handler, you must determine whether it is appropriate to allow a change in the current page, update the CurrentPageIndex property, and call DataBind(). DataGridPageChangedEventArgs no longer has an OldPageIndex property, since this is same as the CurrentPageIndex property on the control itself.  

Old Code:

private void DataGrid_PageIndexChanged(object sender, DataGridPageChangedEventArgs e) {
((DataGrid)sender).DataSource = {your data source};
((DataGrid)sender).DataBind();
}

New Code:

private void DataGrid_PageIndexChanged(object sender, DataGridPageChangedEventArgs e) {
((DataGrid)sender).DataSource = {your data source};
((DataGrid)sender).CurrentPageIndex = e.NewPageIndex;
((DataGrid)sender).DataBind();
}

 As a result of this change, you can now prevent changes in the page index simply by not doing anything in your event handler.

         The DataBindings property and HasDataBindings() method on Control have moved into IDataBindingsAccessor. These properties should not exist on the public interface of a Control, since they are intended for use by the designer only. They are now part of IdataBindingsAccessor, which is implemented privately on Control. HtmlControlDesigner now has a DataBindings public property which control designers can use as well.  

Old Code:

Control c;
DataBindinGCollection bindings = c.DataBindings;

New Code:

Control c;
DataBindinGCollection bindings = ((IDataBindingsAccessor)c).DataBindings;

With a control designer, this.DataBindings will return the data-binding collection of the control associated with the designer.

         A DataMember property was added to data-bound controls. This is an addition of new functionality, instead of a breaking change. The DataSource property for HtmlSelect, ListBox, DropDownList, CheckBoxList, RadioButtonList, Repeater, DataList and DataGrid has been changed to an object (see notes that follow), so as to allow both IEnumerable and DataSet instances to be used as a data source. All of these controls now have a string DataMember property that is used when the DataSource property is assigned a DataSet.

Rules for resolving the DataSource:

1)If the data source is a DataSet:

a)If the DataMember property is specified, use it to determine which DataTable within the DataSet is to be used.

b)If the DataMember property is not specified, use the DataTable with index 0.

2)If the data source is not a DataSet:

a)Use the DataSource directly. 

         The DataGrid no longer has a PageCount property. The presence of a PageCount property implies the presence of a DataSource instance at all times, but this is not the case. The only time a DataSource exists is within a call to DataBind(). It is useful only when you create a Pager item; in that case a PagedDataSource is passed in, from which the page count is available. 

Old Code:

dataGrid.DataSource = myDataSet.Tables["Table1"].DefaultView;

New Code:

dataGrid.DataSource = myDataSet;
dataGrid.DataMember = "Table1";

DataSource is now of type Object so as to support both IEnumerable and DataSet instances as data sources. This will eventually be changed back to IEnumerable, once DataSet implements it.

         The signature of IConfigSectionHandler has changed. Support for ConfigXmlInput has been replaced with support for System.Xml.XmlReader instead.

         State has been renamed to ViewState in the Control framework. The following have changed.

 
Old form New form MaintainState EnableViewState State ViewState LoadState LoadViewState LoadStateRecursive LoadViewStateRecursive SaveState SaveViewState SaveStateRecursive SaveViewStateRecursive IStateManager::Mark -> TrackState Control::Mark -> TrackViewState ControlState enum: StateLoaded ViewSta

[1] [2] [3] [4] [5] [6] [7]  下一页

打印本文 打印本文 关闭窗口 关闭窗口