Web Parts and SQL CE

I have tried and failed to include a simple Web Parts sample for ASP.NET Web Forms Basics and Esoterics in my studio. The error is:

Exception information: 
    Exception type: SqlException
    Exception message: Failed to generate a user instance of SQL Server due to a failure in starting the process for the user instance. The connection will be closed.
   at System.Data.SqlClient.SqlInternalConnection.OnError(SqlException exception, Boolean breakConnection)
   at System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning()
   at System.Data.SqlClient.TdsParser.Run(RunBehavior runBehavior, SqlCommand cmdHandler, SqlDataReader dataStream, BulkCopySimpleResultSet bulkCopyHandler, TdsParserStateObject stateObj)

It concerns me that System.Data.SqlClient is in use here instead of System.Data.SqlServerCe.4.0, which is specified in the connection string. This setting comes from installing the NuGet package, System.Web.Providers based on Scott Hanselman’s “Introducing System.Web.Providers—ASP.NET Universal Providers for Session, Membership, Roles and User Profile on SQL Compact and SQL Azure.” I have yet to find an article about using Web Parts with SQL CE.

Related Resources

ASP.NET Web Forms Interview Questions

иконопис
MVP Chalermvong and his session - ASP.NET Performance Up!

Learning how to work with ASP.NET Web Forms is the other thing of “New Things Learned in the Labor Camp”… I’ve avoided confronting ASP.NET “classic” directly for years. Instead, I made the right decision to learn things about Web programming and Web design that Microsoft notoriously undervalued in its professional communication for years until the rise of Scott Guthrie from ASP.NET “classic” to ASP.NET MVC.

Sadly, there is a job market full of IT shops that are deeply invested (often emotionally invested) in ASP.NET “1.9”—the way of seeing the Web through the Microsoft looking glass just before ASP.NET 2.0 was released in 2005.

For years I’ve “run away” from confronting ASP.NET Web Forms directly. The following interview questions I’ve slapped together “finally” engage—directly. By the way to show that I’m super serious about this matter, I’ve literally spent hours over about two weeks building samples for ASP.NET for Web Forms in my studio.

What are ASP.NET Web Forms?

ASP.NET Web Forms is a technology that breaks down a plain-old HTTP Request into a series of clearly defined events (classified broadly under initialization, load and render)—these events describe the “life cycle” of a familiar model, the data-entry form in a Web page. ASP.NET is based on the event-driven programming paradigm made popular and traditional by Microsoft in the 1990s.

What is a ‘Post Back’?

The ‘Post Back’ is the concept developed by Microsoft that stands between the post HTTP verb and the first event recognized by an ASP.NET Page. Typically, the Page.IsPostBack Boolean is checked in the Page.OnLoad event handler. When Page.IsPostBack == false then the get HTTP verb is the request. Microsoft has defined a conventional Jscript function, __doPostBack(), that invokes the ‘Post Back.’ ASP.NET Web Forms seem crude and extravagant in the 21st century when a page-level post action is regarded as expensive and disruptive (ASP.NET AJAX was supposed to remedy this).

Why do ASP.NET controls require a parent form?

Without a parent form element, the ‘Post Back’ concept is not implemented. Conventional hidden fields in the form store event metadata (__EVENTTARGET, __EVENTARGUMENT, __VIEWSTATE).

See also:TRULY Understanding ViewState

What is the AutoPostBack property?

The AutoPostBack property is a Boolean that is apparently defined independently and conventionally in the System.Web.UI.WebControls.ListControl, System.Web.UI.WebControls.CheckBox and System.Web.UI.WebControls.TextBox. When AutoPostBack == true an event associated with these controls (select, check, blur) will cause a Post Back.

See also:
System.Web.UI.PostBackOptions and System.Web.UI.Page.AutoPostBackControl.


super smart msft peeps

What is a Cross-Page Post Back?

By default, an ASP.NET page “posts back” to itself (frequently). A Cross-Page Post Back declares that one Web Form should post to another Web Form—not back to itself. Input captured in the posting page can be captured in the receiving page via the Page.PreviousPage property.

Tip: The Page.IsCrossPagePostBack property is always null. During a cross page Post Back Page.PreviousPage.IsCrossPagePostBack will be true.

See also:
Button.PostBackUrl.

What is a Server Transfer?

An ASP.NET Server Transfer allows a Page executing on the Server to Transfer execution to another Page. It can be thought of as a call to another procedure from the currently executing procedure. In terms of a POCO class, a Server Transfer is a method call in a procedure of one class with a member from another class—the catch is that no arguments can be passed in the method call. After a Server Transfer, the new page running has access to all of the Request, Session and Application-scope data in the old page. Importantly, there is a Page.PreviousPage property which can be used with FindControl() to locate controls on the old page.

According to Microsoft MVP Karl Moore, “So, in brief: Response.Redirect simply tells the browser to visit another page. Server.Transfer helps reduce server requests, keeps the URL the same and, with a little bug-bashing, allows you to transfer the query string and form variables. …Don’t confuse Server.Transfer with Server.Execute, which executes the page and returns the results. It was useful in the past, but, with ASP.NET, it’s been replaced with fresher methods of development. Ignore it.”

See also:ASP.NET Server.Transfer Method

What is a Master Page?

The ASP.NET Master helps keep Web Forms DRY. They share visual elements among several ASP.NET pages providing the “consistent look and feel” Web designers expect. ASP.NET Master pages also centralize HTML page “meta” information, much of the angle-bracketed ceremony that make Web page markup noisy.

How does a Master Page affect the Control.FindControl function?

The ASP.NET Master adds one or more ContentPlaceHolder controls to the visual tree. These in turn demand Content controls, which implement INamingContainer—a “naming container” affects the ID attributes of child controls “inside” the container. So: a control named foo inside a naming container, bar, can be located by Control.FindControl("bar$foo") where Control would be an instance of the Master page in our example.


The ASP.NET Dream Team

How do Web Forms handle Validation?

ASP.NET handles Validation with PostBack-dependent server controls. These server controls share a ControlToValidate property, pointing to the input-related server control to Validate. There are validation controls for marking input as required, checking input for a data type, testing input with a Regular Expression and testing input with custom code.

One little annoyance: custom validators don’t work with blank input—so they must be paired with the validation control for marking input as required (RequiredFieldValidator).

What are Validation groups?

Validation groups allow more than one “validation context” to exist in a Web Form. For example, a layout with a GridView might have an EditItemTemplate with one Validation Group for editing while another form used for inserting new rows into the grid will have another Validation Group. Validation groups are declared with the ValidationGroup property.

What is a “Partial Page Update”?

The “Partial Page Update” is made possible with the UpdatePanel and the ScriptManager, which is the heart of ASP.NET AJAX. This extension to ASP.NET introduced in version 2.0 dramatically reduces the need to do the “classic” PostBack by implementing the “asynchronous PostBack” a.k.a. the “Partial Page Update.”

Flippant Remarks about ASP.NET HTTP Context


K Scott Allen

What I notice about ASP.NET HttpContext:

  • The ApplicationInstance property has some of the events that have seemed to me to appear from nowhere in Global.asax.cs—by the way, Application_Start is not there—what is there are a bunch of authentication events (leading me quite ‘naturally’ to the subject of authentication).
  • For the Items collection, the MSDN documentation explains that the collection “…can be used to organize and share data between an IHttpModule interface and an IHttpHandler interface during an HTTP request…” My opinion: this collection is meant to be used for Module programming—not for passing object-boxed data between pages (especially when these data can be accessed with the Page.PreviousPage property).
  • The Profile property sitting in HTTP Context helps me distinguish between Profiles and Membership—it’s the Membership processes that result in User Profile data.
  • The Cache property refers to the second type of out-of-the-box ASP.NET caching, application data caching (output caching, by the way, is the first). Based on my current level of experience with the innards of ASP.NET I assume that the Cache property is still useful when more advanced distributed caching solutions, like Velocity, are in use.

Related Links

One WCF Service for Rest and Binary

икони на светци

The sweet spot of the moment is standing in a WCF design that tries to stay with one service contract per tiny application (concern). The motivation to do this is for ease of web.config maintenance where there will be one service declaration in the collection of services in system.serviceModel.

The desire for one service definition leads (me) to learning how to build a service contract that supports binaryMessageEncoding and text-based “rest” WebGet or WebInvoke. This desire is reinforced by the following observations (seen in Visual Studio):

  • Adding a new WCF Service item for the first time auto-generates behaviors and serviceHostingEnvironment declarations in system.serviceModel. No service declaration is generated—which is makes the configuration more maintainable.
  • Adding a new AJAX-enable WCF Service item generates a service definition because it needs an explicit endpoint definition with an AJAX-friendly binding and behavior configuration.
  • Adding a new AJAX-enable WCF Service item after adding a WCF Service item causes the first WCF service to break—so the idea of trying to get MEX and rest by making a few Visual Studio moves with “smart” defaults (without Glenn Block’s help) is not realistic.

The System Service Model Service Definition

Here is that single service declaration promised earlier:

<services>
    <service name="Songhay.Web.HostRoot.Services.WcfServiceOne"
        behaviorConfiguration="mexServiceBehavior">
        <endpoint address="mex" binding="mexHttpBinding"
            contract="IMetadataExchange" />
        <endpoint address="" binding="customBinding"
            bindingConfiguration="customHttpBinding"
            contract="Songhay.Web.HostRoot.Services.IWcfServiceOne" />
        <endpoint address="json" behaviorConfiguration="ajaxBehavior"
            binding="webHttpBinding"
            contract="Songhay.Web.HostRoot.Services.IWcfServiceOne" />
    </service>
</services>

The customHttpBinding and ajaxBehavior most distinguish this little design. Respectively, we have:

<bindings>
    <customBinding>
        <binding name="customHttpBinding">
            <binaryMessageEncoding />
            <httpTransport />
        </binding>
    </customBinding>
</bindings>

and

<endpointBehaviors>
    <behavior name="ajaxBehavior">
        <enableWebScript />
        <webHttp helpEnabled="true"/>
    </behavior>
</endpointBehaviors>

Also, notice that the customBinding and webHttpBinding are not sharing the same path such that http://localhost/MyService.svc/ would be for binary transport and http://localhost/MyService.svc/json/ would be for the AJAX behavior.

Selected Resources

Today’s @elijahmanor links…


If memory serves...