.NET Questions and Solutions

As a software engineer, I focus on .NET, especially asp.net, C#, WCF and so on, and I am also very interested in Search Engine Optimization.

Entries Tagged ‘control’

Fatal Exception Error When Opening or Closing Control Panel

Symptoms
Any or all of the following symptoms may occur:When you attempt to open or close Control Panel, or when you removenetwork components in Network properties and then restart Windows, you receive one of the following error messages:

A fatal exception 0E has occurred at 0028:xxxxxxxx in VXD IFSMGR(04)+ 0000D4F1.
The current application will be terminated.
-or-

A fatal exception 0E has occurred at 0028:xxxxxxxx in VXD IFSMGR(03) + 000CF7C.
The current application will be terminated.
The <0028:xxxxxxxx> value represents the enhancedinstruction pointer to the code segment; the 32-bit address is the actualaddress where the exception occurred and can vary from computer to computer.After you receive one of these error messages, you can still use Control Panel, but the Speaker icon may no longer appear on the taskbar. This behavior may also occur in Safe mode.
When you start Windows, you receive the following error message:

A fatal exception 0E has occurred at 028:C0282dB0 in VxD IFSMGR(03) + 0000 CF7C
The current application will be terminated.Windows 95 or Windows 98 Setup stops responding (hangs) while Control Panel is being configured.
Resolution
This behavior can occur if a scanner is installed in your computer, and the Vhpscand.vxd file is located in the Windows\System folder instead of the Windows\System\Iosubsys folder.

BUG: You receive a “System.Runtime.InteropServices.COMException” message when you bind an ImageList ActiveX control to a CoolBar ActiveX control

Symptoms
In Microsoft Visual Studio 2005 or in Microsoft Visual Studio .NET, when you set the ImageList property of the CoolBar ActiveX control to the ImageList ActiveX control, and then you run the application, you receive the following exception:

An unhandled exception of type ‘System.Runtime.InteropServices.COMException’ occurred in axinterop.comctl3.dll
Additional information: Invalid property value. Note You cannot set the ImageList property of the CoolBar ActiveX control in the Properties window.
Resolution
Microsoft Visual Basic 2005, Microsoft Visual Basic .NET, and Microsoft Visual C# .NET interpret the ImageList property of the CoolBar ActiveX control as a read-only property. Therefore, Visual Basic 2005, Visual Basic .NET, and Visual C# .NET throw an exception when you set the ImageList property of the CoolBar ActiveX control to the ImageList ActiveX control.

BUG: Microsoft Date Time Picker Control Causes Exception Error

Symptoms
If you have a Microsoft Date and Time ActiveX control instantiated within aToolBar and the focus is set to the Date and Time control, some of the ALTkey combinations cause an exception error, and Visual FoxPro shuts down.
Resolution
Microsoft has confirmed this to be a bug in the Microsoft products listedat the beginning of this article.

BUG: “Unhandled exception in EXENAME.EXE(OLE32.DLL): 0xC0000005: Access Violation” when you use an ATL Composite control on computers without Visual C++ installed

Symptoms
When you create an ATL Composite control with other ActiveX controls embedded in it, you may get an access violation in Ole32.dll. Usually, a message box is displayed with the following error message:

Unhandled exception in EXENAME.EXE(OLE32.DLL): 0xC0000005: Access ViolationYou may also see a Web Browser control displayed with the following message, instead of the child ActiveX control:
This page cannot be displayed. Usually, these controls work correctly on computers with Visual C++ installed, but they do not work on computers without Visual C++ installed.
Resolution
The ActiveX controls embedded in the Composite control may be licensed controls. Composite controls and ATL containment do not directly support creation of licensed controls.
When the Composite control attempts to create a licensed control on a computer without providing a run-time license, the Composite control fails with an HRESULT of 0×80040112 (CLASS_E_NOTLICENSED – Class is not licensed for use). The default handling of this failure creates a Web Browser control; the default handling also tries to initialize the Web Browser control with persisted properties of the licensed control. This mismatch of properties may result in an access violation in the Ole32.dll file.
If there is no access violation, the Web Browser control attempts to navigate to a URL that is the string representation of the licensed control’s CLSID. This action results in the error message “The page cannot be displayed.”

ASP.NET data binding overview

Symptoms
This article provides an introduction to ASP.NET data binding.
For additional ASP.NET overviews, see the following Microsoft Knowledge Base article:
305140?(http://support.microsoft.com/kb/305140/) ASP.NET roadmap
Resolution
With ASP.NET data binding, you can bind any server control to simple properties, collections, expressions and/or methods. When you use data binding, you have more flexibility when you use data from a database or other means.
This article addresses the following data binding topics: Data binding essentials<%# %> SyntaxPage.DataBind() versus Control.DataBind()Data-bound list controlsRepeater controlDataList controlDataGrid controlAccessing dataDataSet dlassDataReader dlassBinding in list control templatesDataBinder.Eval methodExplicit castingItemDataBound event
Data binding essentials<%# %> Syntax ASP.NET introduces a new declarative syntax, <%# %>. This syntax is the basis for using data binding in an .aspx page. All data binding expressions must be contained within these characters. The following list includes examples of simple data binding from multiple sources: Simple property (syntax for a customer):

<%# custID %> Collection (syntax for an order):

<asp:ListBox id=”List1″ datasource=’<%# myArray %>’ runat=”server”> Expression (syntax for a contact):

<%# ( customer.First Name + ” ” + customer.LastName ) %> Method result (syntax for the outstanding balance):

<%# GetBalance(custID) %> In the preceding examples, the inline <%# %> tags indicate where the information from a specific data source is to be placed in the .aspx page. The following data binding example uses a TextBox Web server control:

<asp:textbox id=txt text=”<%# custID %>” runat=server /> For more information about data binding syntax, see the following .NET Framework Software Development Kit (SDK) documentation:
Data Binding Expression Syntax
http://msdn2.microsoft.com/en-us/library/bda9bbfx(vs.71).aspx(http://msdn2.microsoft.com/en-us/library/bda9bbfx(vs.71).aspx)Page.DataBind() versus Control.DataBind() After the particular data sources have been determined and set for the objects on the .aspx page, you must bind the data to these data sources. You can use the Page.DataBind or the Control.DataBind method to bind the data to the data sources.
Both methods work similarly. The main difference is that all data sources are bound to their server controls after the Page.DataBind method is called. No data is rendered to the control until you explicitly call either the DataBind method of the Web server control or until you invoke the page-level Page.DataBind method. Typically, Page.DataBind (or DataBind) is called from the Page_Load event.
For more information about the DataBind method, see the following .NET Framework SDK documentation: Control.DataBind Method
http://msdn.microsoft.com/en-us/library/w5e5992d.aspx(http://msdn.microsoft.com/en-us/library/w5e5992d.aspx)
Data-bound list controls The list controls are special Web server controls that can bind to collections. You can use these controls to display rows of data in a customized template format. All list controls expose the DataSource and the DataMember properties, which are used to bind to collections.
These controls can bind their DataSource property to any collection that supports the IEnumerable, the ICollection, or the IListSource interface.
Repeater control The Repeater control is a templated, data-bound list. The Repeater control is “lookless;” that is, it does not have any built-in layout or styles. Therefore, you must explicitly declare all HTML layout, formatting, and style tags in the control’s templates.
The following code samples demonstrate how you can use one list control, the Repeater control, to display data:
NOTE: You must modify the parameters of the connection string as necessary for your environment.
Visual Basic .NET

<%@ Page Language=”vb” %><%@ Import Namespace=”System.Data” %><%@ Import Namespace=”System.Data.SqlClient” %><script runat=”server”>Sub Page_Load(sender As Object, e As EventArgs)Dim cnn As SqlConnection = New SqlConnection(“server=(local);” & _”database=pubs;Integrated Security=SSPI”)Dim cmd As SqlDataAdapter = New SqlDataAdapter(“select * from authors”, cnn)Dim ds As DataSet = New DataSet()cmd.Fill(ds)Repeater1.DataSource = dsRepeater1.DataBind()End Sub</script><html><body><form id=”Form1″ method=”post” runat=”server”><asp:Repeater id=”Repeater1″ runat=”server”><ItemTemplate><%# DataBinder.Eval(Container.DataItem,”au_id”) %><br> </ItemTemplate></asp:Repeater></form></body></html> Visual C# .NET

<%@ Page language=”c#” %><%@ Import Namespace=”System.Data” %><%@ Import Namespace=”System.Data.SqlClient” %><script runat=”server”>void Page_Load(Object sender, EventArgs e) {SqlConnection cnn = newSqlConnection(“server=(local);database=pubs;Integrated Security=SSPI”);SqlDataAdapter da = new SqlDataAdapter(“select * from authors”, cnn);DataSet ds = new DataSet();da.Fill(ds, “authors”);Repeater1.DataSource = ds.Tables["authors"];Repeater1.DataBind();}</script><html><body><form id=”WebForm2″ method=”post” runat=”server”><asp:Repeater id=”Repeater1″ runat=”server”><ItemTemplate><%# DataBinder.Eval(Container.DataItem,”au_id”) %><br> </ItemTemplate></asp:Repeater></form></body></html> Visual J# .NET

<%@ Page language=”VJ#” %><%@ Import Namespace=”System.Data” %><%@ Import Namespace=”System.Data.SqlClient” %> <script runat=”server”>void Page_Load(Object sender, EventArgs e) {SqlConnection cnn = new SqlConnection(“server=(local);database=pubs;IntegratedSecurity=SSPI”);SqlDataAdapter da = new SqlDataAdapter(“select * from authors”, cnn);DataSet ds = new DataSet();da.Fill(ds, “authors”);DataTableCollection dtc = ds.get_Tables();int index = dtc.IndexOf(“authors”);Repeater1.set_DataSource(dtc.get_Item(index));Repeater1.DataBind();}</script><html><body><form id=”WebForm2″ method=”post” runat=”server”><asp:Repeater id=”Repeater1″ runat=”server”><ItemTemplate><%# DataBinder.Eval(Container.DataItem,”au_id”) %><br></ItemTemplate></asp:Repeater></form></body></html> For more information about the Repeater control, see the following .NET Framework SDK documentation:
Repeater Web Server Control
http://msdn.microsoft.com/en-us/library/x8f2zez5.aspx(http://msdn.microsoft.com/en-us/library/x8f2zez5.aspx)DataList control The DataList class is a feature-rich, templated, data-bound list. You can modify the templates to customize this control. Unlike the Repeater control, DataList supports directional rendering and can optionally render in an HTML table at run time.
For more information about the DataList control, see the following .NET Framework SDK documentation:
DataList Web Server Control
http://msdn.microsoft.com/en-us/library/9cx2f3ks(VS.85).aspx(http://msdn.microsoft.com/en-us/library/9cx2f3ks(VS.85).aspx)DataGrid control The DataGrid control is a fully featured, multicolumn, data-bound grid. To customize the layout of individual columns in the DataGrid, you can set the column type to “templated” and modify the column’s templates. The DataGrid control can render without templates, which makes this control ideal for reporting scenarios. DataGrid also supports selection, editing, deletion, paging, and sorting by column and button columns.
For more information about the DataGrid control, see the following .NET Framework SDK documentation:
DataGrid Web Server Control
http://msdn.microsoft.com/en-us/library/aa710742(VS.71).aspx(http://msdn.microsoft.com/en-us/library/aa710742(VS.71).aspx)
Accessing data This section describes how to access data from a database and bind the data to list controls. You can use the DataSet or the DataReader class to obtain data from a database. DataSet class A DataSet contains a complete representation of data, including the table structure, the relationships between tables, and the ordering of the data. DataSet classes are flexible enough to store any kind of information from a database to an Extensible Markup Language (XML) file. DataSet classes are stateless; that is, you can pass these classes from client to server without tying up server connection resources. The following code demonstrates how to use a DataSet to bind data to a control:
NOTE: You must modify the parameters of the connection string as necessary for your environment.
Visual Basic .NET

Dim cnn As SqlConnection = New SqlConnection(“server=(local);” & _”database=pubs;Integrated Security=SSPI”)Dim cmd As SqlDataAdapter = New SqlDataAdapter(“select * from authors”, cnn)Dim ds As DataSet = New DataSet()cmd.Fill(ds)MyRepeater.DataSource = dsMyRepeater.DataBind() Visual C# .NET

SqlConnection cnn = new SqlConnection(“server=(local);database=pubs;Integrated Security=SSPI”); SqlDataAdapter da = new SqlDataAdapter(“select * from authors”, cnn); DataSet ds = new DataSet(); da.Fill(ds);MyRepeater.DataSource = ds;MyRepeater.DataBind(); Visual J# .NET

SqlConnection cnn = new SqlConnection(“server=(local);database=pubs;Integrated Security=SSPI”); SqlDataAdapter da = new SqlDataAdapter(“select * from authors”, cnn); DataSet ds = new DataSet(); da.Fill(ds); MyRepeater.set_DataSource(ds);MyRepeater.DataBind(); For more information about the DataSet class, see the following .NET Framework SDK documentation:
DataSet Class
http://msdn2.microsoft.com/en-us/library/system.data.dataset(vs.71).aspx(http://msdn2.microsoft.com/en-us/library/system.data.dataset(vs.71).aspx)DataReader class Conversely, if you only need to display (and not change) the data that is to be rendered, a DataReader class may be a better solution. For example, it is better to use a DataReader for a DropDownList control because the DataReader is a forward-only data cursor. The following code demonstrates how to use a SqlDataReader class to bind data to a control:
Visual Basic .NET

Dim cnn As SqlConnection = New SqlConnection(“server=(local);” & _”database=pubs;Integrated Security=SSPI”)Dim cmd As SqlCommand = New SqlCommand(“select * from authors”, cnn)cnn.Open()MyRepeater.DataSource = cmd.ExecuteReader(CommandBehavior.CloseConnection)MyRepeater.DataBind() Visual C# .NET

SqlConnection cnn = new SqlConnection(“server=(local);database=pubs;Integrated Security=SSPI”);SqlCommand cmd = new SqlCommand(“select * from authors”, cnn);cnn.Open();MyRepeater.DataSource = cmd.ExecuteReader(CommandBehavior.CloseConnection);MyRepeater.DataBind(); Visual J# .NET

SqlConnection cnn = new SqlConnection(“server=(local);database=pubs;Integrated Security=SSPI”); SqlCommand cmd = new SqlCommand(“select * from authors”, cnn); cnn.Open();MyRepeater.set_DataSource(cmd.ExecuteReader(CommandBehavior.CloseConnection));MyRepeater.DataBind(); For more information about the SqlDataReader class and data access with ASP.NET, see the following topics in the .NET Framework SDK documentation:
SqlDataReader Class
http://msdn.microsoft.com/en-us/library/system.data.sqlclient.sqldatareader.aspx(http://msdn.microsoft.com/en-us/library/system.data.sqlclient.sqldatareader.aspx)
Developing High-Performance ASP.NET Applications
http://msdn2.microsoft.com/en-us/library/5dws599a(vs.71).aspx(http://msdn2.microsoft.com/en-us/library/5dws599a(vs.71).aspx)
Binding in list control templates You can use templates in the list controls to bind and to customize individual records of a data source. This section includes three methods to do this. DataBinder.Eval method When the data source works with data that is returned from a database, the data source may contain numerous pieces of information. You can use the generic DataBinder.Eval method to return data. In the following code sample, the “au_id” field is returned from the data source of the container object:

<%# DataBinder.Eval(Container.DataItem,”au_id”) %> For more information about the DataBinder.Eval method, see the following .NET Framework SDK documentation:
DataBinder.Eval Method
http://msdn.microsoft.com/en-us/library/4hx47hfe.aspx(http://msdn.microsoft.com/en-us/library/4hx47hfe.aspx)Explicit casting If you need more control, use explicit casting. An explicit conversion uses a type conversion keyword. These keywords act as functions, but the compiler generates the code inline. Therefore, execution is slightly faster than with a function call. The following code samples use explicit casting:
Visual Basic .NET

‘ DataTable as the DataSource<%# CType(Container.DataItem, System.Data.DataRowView)(“au_id”) %>’ DataReader as the DataSource<%# CType(Container.DataItem, System.Data.Common.DbDataRecord)(“au_id”) %>’ DataReader as the DataSource<%# CType(Container.DataItem, System.Data.Common.DbDataRecord)(0) %> Visual C# .NET

// DataTable as the DataSource<%# ((System.Data.DataRowView)Container.DataItem)["au_id"] %> // DataReader as the DataSource<%# ((System.Data.Common.DbDataRecord)Container.DataItem)["au_id"] %>// DataReader as the DataSource<%# ((System.Data.Common.DbDataRecord)Container.DataItem)[0] %> Visual J# .NET

// DataTable as the DataSource<%# ((System.Data.DataRowView)Container.DataItem)["au_id"] %> // DataReader as the DataSource<%# ((System.Data.Common.DbDataRecord)Container.DataItem)["au_id"] %>// DataReader as the DataSource<%# ((System.Data.Common.DbDataRecord)Container.DataItem)[0] %> Note that the preceding samples use either a DataTable, which is a subset of a DataSet, or DataReader as a data source. ItemDataBound event You can also use the ItemDataBound event of the control to bind the data. This event occurs when an item is data bound to the control. The following HTML code sample defines a Repeater control with an ItemTemplate:

<asp:repeater id=rptr runat=server><itemtemplate><asp:label id=lblAuthorID runat=server /></itemtemplate></asp:repeater> The following methods are required in your page:
Visual Basic .NET

public Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs)’TODO: Retrieve data from a database,’and bind the data to a list control.End Subpublic Sub rptr_OnItemDataBound(ByVal sender As Object, _ByVal e As System.Web.UI.WebControls.RepeaterItemEventArgs) Handles rptr.ItemDataBoundDim rec As DataRowViewrec = e.Item.DataItem’Make sure that you have the data.If Not IsDBNull(rec) ThenDim l1 As Labell1 = e.Item.FindControl(“lblAuthorID”)l1.Text = rec(“au_id”).ToString()End IfEnd Sub Visual C# .NET

public void Page_Init(object sender, System.EventArgs e){rptr.ItemDataBound += new RepeaterItemEventHandler(rptr_OnItemDataBound);}public void Page_Load(object sender, System.EventArgs e){// TODO: Retrieve data from a database,// and bind the data to a list control.}public void rptr_OnItemDataBound(object sender, RepeaterItemEventArgs e){System.Data.Common.DbDataRecord rec = (System.Data.Common.DbDataRecord)e.Item.DataItem;if(rec!=null) //Make sure that you have the data.{Label l1 = (Label)e.Item.FindControl(“lblAuthorID”);l1.Text = rec["au_id"].ToString();}} Visual J# .NET

public void Page_Init(Object sender, System.EventArgs e){rptr.add_ItemDataBound(new RepeaterItemEventHandler(rptr_OnItemDataBound));}private void Page_Load(Object sender, System.EventArgs e){// TODO: Retrieve data from a database,// and bind the data to a list control.}public void rptr_OnItemDataBound(Object sender, RepeaterItemEventArgs e){System.Data.Common.DbDataRecord rec = (System.Data.Common.DbDataRecord)e.get_Item().get_DataItem();if (rec != null) //Make sure that you have the data.{Label l1 = (Label)e.get_Item().FindControl(“lblAuthorID”);l1.set_Text(((rec.get_Item(“au_id”)).ToString()));}}

ACC2000: References Not Imported with Objects from Another Database

Symptoms
When you import a Microsoft Access object from one database into anotherdatabase, any reference used by the object is not imported, and you mustre-create the reference in the target database. For example, if you insertan ActiveX control on a form, Microsoft Access automatically creates areference to the .ocx file for that control. If you then open anotherdatabase and import the form that contains the ActiveX control from thefirst database, the reference to the .ocx file is not imported with theform. This behavior also occurs when you export an object.
Resolution
A reference is not imported or exported with an object because it is notspecific to the object; instead, a reference is specific to the project ofa database.