WordPress: Briefly unavailable for scheduled maintenance. Check back in a minute.
I got this error message when I tried to upgrade to the latest version of wordpress.
It is very easy to fix, all you need to do is to remove the file " .maintenance" in the root folder.
(1/3) ListView events, ItemDataBound, ItemCreated
Below are the screenshots about a user control that is using the .NET ListView control.
The ListView control contains many different events. In these examples, the EDIT button, REMOVE button, ADD button, and SAVE button click events are handled respectively.
Of course, there are many ways of implementations to get the job done, as far as I believed, using these ItemDataBound, ItemEditing, ItemDeleting, ItemCanceling, ItemUpdating, and ItemInserting are the easiest way.
Before implementing the code, design the UI first.
<table> <thead> <tr> <th><asp:Literal ID="LitHost" runat="server" /></th> <th><asp:Literal ID="LitPointsTo" runat="server" /></th> <th><asp:Literal ID="LitTtl" runat="server" /></th> <th><asp:Literal ID="LitActions" runat="server" /></th> </tr> </thead> <tbody> <asp:ListView ID="LstItems" runat="server"> <LayoutTemplate> <tr id="itemPlaceHolder" runat="server" /> </LayoutTemplate> <ItemTemplate> <tr> <td><asp:Literal ID="LitHost" runat="server" /></td> <td><asp:Literal ID="LitPointsTo" runat="server" /></td> <td><asp:Literal ID="LitTtl" runat="server" /></td> <td> <asp:LinkButton CommandName="Edit" ID="BtnEdit" runat="server" /> <asp:LinkButton CommandName="Delete" ID="BtnRemove" runat="server" /> </td> </tr> </ItemTemplate> <EditItemTemplate> <tr> <td><asp:TextBox ID="TxtHost" runat="server" /></td> <td><asp:TextBox ID="TxtPointsTo" runat="server" /></td> <td><asp:DropDownList ID="DdlTtl" runat="server" /></td> <td> <asp:LinkButton CommandName="Update" ID="BtnSave" runat="server" /> <asp:LinkButton CommandName="Cancel" ID="BtnCancel" runat="server" /> </td> </tr> </EditItemTemplate> <InsertItemTemplate> <tr> <td><asp:TextBox ID="TxtNewHost" runat="server" /></td> <td><asp:TextBox ID="TxtNewPointsTo" runat="server" /></td> <td><asp:DropDownList ID="DdlNewTtl" runat="server" /></td> <td><asp:LinkButton ID="BtnAdd" CommandName="Insert" runat="server" /></td> </tr> </InsertItemTemplate> </asp:ListView> </tbody> </table>
In the code-behind, we need to hook up the ItemDataBound event, and bind the data source.
LstItems.ItemDataBound += new EventHandler<ListViewItemEventArgs>(LstItems_ItemDataBound); LstItems.DataSource = DnsCollection; LstItems.DataBind();
It is more flexible to handle the ItemDataBound event in the code-behind than binding the data source in the UI.
protected void LstItems_ItemDataBound(object sender, ListViewItemEventArgs e) { var item = e.Item; if (item.ItemType == ListViewItemType.DataItem) { var currentDnsRecord = (DnsRecordItem)(item as ListViewDataItem).DataItem; // When Displaying the items if (item.DataItemIndex != LstItems.EditIndex) { var litHost = item.FindControl<Literal>("LitHost"); var litPointsTo = item.FindControl<Literal>("LitPointsTo"); var litTtl = item.FindControl<Literal>("LitTtl"); litHost.Text = currentDnsRecord.HostName; litPointsTo.Text = currentDnsRecord.PointsTo; litTtl.Text = currentDnsRecord.TimeToLive; } else { // When rendering Edit item. var txtHost = item.FindControl<TextBox>("TxtHost"); var txtPointsTo = item.FindControl<TextBox>("TxtPointsTo"); var ddlTtl = item.FindControl<DropDownList>("DdlTTL"); txtHost.Text = OldDnsRecord.HostName; txtPointsTo.Text = OldDnsRecord.PointsTo; BindDdlTimeToLive(ddlTtl, OldDnsRecord.TimeToLive); } } }
If you are not quite sure the FindControl, please check my previous post, FindControl() Extention methods.
On the other hand, when you want to do something before ItemDataBound event, you can create this ItemCreated event handler.
LstItems.ItemCreated += new EventHandler<ListViewItemEventArgs>(LstItems_ItemCreated);
ItemCreated is happened when the ListView is created, and when the data items are bound to the control.
ItemCreated is raised before the ItemDataBound event.
protected void LstItems_ItemCreated(object sender, ListViewItemEventArgs e) { var item = e.Item; if (item.ItemType == ListViewItemType.DataItem) { } else if (item.ItemType == ListViewItemType.InsertItem) { } }
(2/5) ListView events, ItemInserting, ItemDeleting
In order to have this ADD button work, what we need is to wire the events first in the page's code behind.
LstItems.ItemInserting += new EventHandler<ListViewInsertEventArgs>(LstItems_ItemInserting);
LstItems.ItemDeleting += new EventHandler<ListViewInsertEventArgs>(LstItems_ItemDeleting);
LstItems.InsertItemPosition = InsertItemPosition.LastItem;
And usually, we will have this insert template either in the first item of this ListView or the last item. In this example, it is in the last item.
Button "Add" click.
protected void LstItems_ItemInserting(object sender, ListViewInsertEventArgs e)
{
if (!Page.IsValid)
return;
var txtNewHost = e.Item.FindControl<TextBox>("TxtNewHost");
var txtNewPointsTo = e.Item.FindControl<TextBox>("TxtNewPointsTo");
var ddlNewTtl = e.Item.FindControl<DropDownList>("DdlNewTTL");
var host = txtNewHost.Text;
var pointsTo = txtNewPointsTo.Text;
var ttl = ddlNewTtl.SelectedValue;
var result = AddNewRecord();
if (result == Status.Ok)
{
// Rebind the ListView
}
else
{
// Do error handling
}
}
Button "Remove" click.
protected void LstItems_ItemDeleting(object sender, ListViewInsertEventArgs e)
{
var item = LstItems.Items[e.ItemIndex];
var result = RemoveRecord();
if (result == Status.Ok)
{
LstItems.EditIndex = -1;
// Rebind the ListView
}
else
{
// Do error handling
}
}
(3/3) ListView events, ItemEditing, ItemCanceling, ItemUpdating
Same for this Edit Record, Save Record and Cancel button click events.
Wire the events in the code-behind first.
LstItems.ItemEditing += new EventHandler<ListViewItemEventArgs>(LstItems_ItemEditing); LstItems.ItemUpdating += new EventHandler<ListViewItemEventArgs>(LstItems_ItemUpdating); LstItems.ItemCanceling += new EventHandler<ListViewItemEventArgs>(LstItems_ItemCanceling);
Button "Edit" click.
protected void LstItems_ItemEditing(object sender, ListViewItemEventArgs e) { var item = LstItems.Items[e.NewEditIndex]; // Save the currently selected item to OldDnsRecord// ReBind the ListView }
Button "Save" click.
protected void LstItems_ItemUpdating(object sender, ListViewItemEventArgs e) { if (!Page.IsValid) return; var txtNewHost = e.Item.FindControl<TextBox>("TxtNewHost"); var txtNewPointsTo = e.Item.FindControl<TextBox>("TxtNewPointsTo"); var ddlNewTtl = e.Item.FindControl<DropDownList>("DdlNewTTL"); var host = txtNewHost.Text; var pointsTo = txtNewPointsTo.Text; var ttl = ddlNewTtl.SelectedValue; var result = UpdateExistingRecord(); if (result == Status.Ok) { LstItems.EditIndex = -1; // Rebind the ListView } else { // Do error handling } }
Button "Cancel" click.
protected void LstItems_ItemCanceling(object sender, ListViewItemEventArgs e) { LstItems.EditIndex = -1; // Rebind the ListView }
ASP.NET Events
- HttpApplication.BeginRequest
- HttpApplication.AuthenticateRequest
- HttpApplication.PostAuthenticateRequest
- HttpApplication.AuthorizeRequest
- HttpApplication.PostAuthorizeRequest
- HttpApplication.ResolveRequestCache
- HttpApplication.PostResolveRequestCache
- HttpApplication.MapRequestHandler
- HttpApplication.PostMapRequestHandler
- HttpApplication.AcquireRequestState
- HttpApplication.PostAcquireRequestState
- HttpApplication.PreRequestHandlerExecute
- Page.FrameworkInitialize
- Page.InitializeCulture
- Page.OnPreInit
- MasterPage.FrameworkInitialize
- MasterPageControl.FrameworkInitialize
- PageControl.FrameworkInitialize
- MasterPageControl.OnInit
- PageControl.OnInit
- MasterPage.OnInit
- Page.OnInit
- Page.OnInitComplete
- Page.LoadPageStateFromPersistenceMedium
If IsPostBack - Page.LoadControlState
If IsPostBack - MasterPageControl.LoadControlState
If IsPostBack, RegisterRequiresControlState was called and control state contains elements - PageControl.LoadControlState
If IsPostBack, RegisterRequiresControlState was called and control state contains elements - MasterPageControl.LoadViewState
If IsPostBack and ViewState contains elements - PageControl.LoadViewState
If IsPostBack and ViewState contains elements - Page.OnPreLoad
- Page.OnLoad
- MasterPage.OnLoad
- MasterPageControl.OnLoad
- PageControl.OnLoad
- {PageControl|MasterPageControl}.OnCustomEvent
If a custom event was fired on a control declared on the page/master page - {PageControl|MasterPageControl}.OnBubbleEvent
If a custom event was fired on a control declared on the page/master page - {Page|MasterPage}.OnBubbleEvent
If a custom event was fired on a control declared on the page/master page - Page.OnBubbleEvent
If a custom event was fired - Page.OnLoadComplete
- ClientCallbackControl.RaiseCallbackEvent
If in a client callback asynchronous request - ClientCallbackControl.GetCallbackResult
If in a client callback asynchronous request - Page.OnPreRender
If not in an asynchronous postback - MasterPage.OnPreRender
If not in an asynchronous postback - MasterPageControl.OnPreRender
If Visible - PageControl.OnPreRender
If Visible and not in an asynchronous postback - Page.OnPreRenderComplete
If not in an asynchronous postback - Page.SaveControlState
If not in an asynchronous postback and RegisterRequiresControlState is called for the page and control state contains additiona values - MasterPageControl.SaveControlState
If not in an asynchronous postback and RegisterRequiresControlState is called for the master page control and control state contains additiona values - PageControl.SaveControlState
If not in an asynchronous postback and RegisterRequiresControlState is called for the page control and control state contains additiona values - Page.SaveViewState
If not in an asynchronous postback - MasterPage.SaveViewState
If not in an asynchronous postback - MasterPageControl.SaveViewState
If not in an asynchronous postback - PageControl.SaveViewState
If not in an asynchronous postback - Page.SavePageStateToPersistenceMedium
If not in an asynchronous postback - Page.OnSaveStateComplete
If not in an asynchronous postback - Page.Render
If not in an asynchronous postback - MasterPage.Render
If not in an asynchronous postback - MasterPageControl.Render
If Visible and not in an asynchronous postback - PageControl.Render
If Visible and not in an asynchronous postback - Page.OnCommitTransaction
If Transaction = Required or RequiresNew and a transaction was committed or no transaction was created - Page.OnAbortTransaction
If Transaction = Required or RequiresNew and a transaction was rolled back - MasterPageControl.OnUnload
- MasterPageControl.Dispose
- PageControl.OnUnload
- PageControl.Dispose
- MasterPage.OnUnload
- MasterPage.Dispose
- Page.OnUnload
- Page.Dispose
- HttpApplication.PostRequestHandlerExecute
- HttpApplication.ReleaseRequestState
- HttpApplication.PostReleaseRequestState
- HttpApplication.UpdateRequestCache
- HttpApplication.PostUpdateRequestCache
- HttpApplication.LogRequest
- HttpApplication.PostLogRequest
- HttpApplication.EndRequest
- HttpApplication.PreSendRequestHeaders
- HttpApplication.PreSendRequestContent
ASP.NET Page life cycle
- Page.OnPreInit
- MasterPageControl.OnInit (for each control on the master page)
- Control.OnInit (for each contol on the page)
- MasterPage.OnInit
- Page.OnInit
- Page.OnInitComplete
- Page.LoadPageStateFromPersistenceMedium
- Page.LoadViewState
- MasterPage.LoadViewState
- Page.OnPreLoad
- Page.OnLoad
- MasterPage.OnLoad
- MasterPageControl.OnLoad (for each control on the master page)
- Control.OnLoad (for each control on the page)
- OnXXX (control event)
- MasterPage.OnBubbleEvent
- Page.OnBubbleEvent
- Page.OnLoadComplete
- Page.OnPreRender
- MasterPage.OnPreRender
- MasterPageControl.OnPreRender (for each control on the master page)
- Control.OnPreRender (for each control on the page)
- Page.OnPreRenderComplete
- MasterPageControl.SaveControlState (for each control on the master page)
- Control.SaveControlState (for each control on the page)
- Page.SaveViewState
- MasterPage.SaveViewState
- Page.SavePageStateToPersistenceMedium
- Page.OnSaveStateComplete
- MasterPageControl.OnUnload (for each control on the master page)
- Control.OnUnload (for each control on the page)
- MasterPage.OnUnload
- Page.OnUnload
C# Questions and Answers – 09
- How big is the datatype int in .NET?
32 bits. - How big is the char?
16 bits (Unicode). - How do you initiate a string without escaping each backslash?
Put an @ sign in front of the double-quoted string. - What are valid signatures for the Main function?
- public static void Main()
- public static int Main()
- public static void Main( string[] args )
- public static int Main(string[] args )
- Does Main() always have to be public?
No. - How do you initialize a two-dimensional array that you don’t know the dimensions of?
- int [, ] myArray; //declaration
- myArray= new int [5, 8]; //actual initialization
- What’s the access level of the visibility type internal?
Current assembly. - What’s the difference between struct and class in C#?
- Structs cannot be inherited.
- Structs are passed by value, not by reference.
- Struct is stored on the stack, not the heap.
- Explain encapsulation
The implementation is hidden, the interface is exposed. - What data type should you use if you want an 8-bit value that’s signed?
sbyte. - Speaking of Boolean data types, what’s different between C# and C/C++?
There’s no conversion between 0 and false, as well as any other number and true, like in C/C++. - Where are the value-type variables allocated in the computer RAM?
Stack. - Where do the reference-type variables go in the RAM?
The references go on the stack, while the objects themselves go on the heap. However, in reality things are more elaborate. - What is the difference between the value-type variables and reference-type variables in terms of garbage collection?
The value-type variables are not garbage-collected, they just fall off the stack when they fall out of scope, the reference-type objects are picked up by GC when their references go null. - How do you convert a string into an integer in .NET?
Int32.Parse(string), Convert.ToInt32() - How do you box a primitive data type variable?
Initialize an object with its value, pass an object, cast it to an object - Why do you need to box a primitive variable?
To pass it by reference or apply a method that an object supports, but primitive doesn’t. - What’s the difference between Java and .NET garbage collectors?
Sun left the implementation of a specific garbage collector up to the JRE developer, so their performance varies widely, depending on whose JRE you’re using. Microsoft standardized on their garbage collection. - How do you enforce garbage collection in .NET?
System.GC.Collect(); - Can you declare a C++ type destructor in C# like ~MyClass()?
Yes, but what’s the point, since it will call Finalize(), and Finalize() has no guarantees when the memory will be cleaned up, plus, it introduces additional load on the garbage collector. The only time the finalizer should be implemented, is when you’re dealing with unmanaged code. - What’s different about namespace declaration when comparing that to package declaration in Java?
No semicolon. Package declarations also have to be the first thing within the file, can’t be nested, and affect all classes within the file. - What’s the difference between const and readonly?
You can initialize readonly variables to some runtime values. Let’s say your program uses current date and time as one of the values that won’t change. This way you declarepublic readonly string DateT = new DateTime().ToString().
- Can you create enumerated data types in C#?
Yes. - What’s different about switch statements in C# as compared to C++?
No fall-throughs allowed. - What happens when you encounter a continue statement inside the for loop?
The code for the rest of the loop is ignored, the control is transferred back to the beginning of the loop. - Is goto statement supported in C#? How about Java?
Gotos are supported in C#to the fullest. In Java goto is a reserved keyword that provides absolutely no functionality. - Describe the compilation process for .NET code?
Source code is compiled and run in the .NET Framework using a two-stage process. First, source code is compiled to Microsoft intermediate language (MSIL) code using a .NET Framework-compatible compiler, such as that for Visual Basic .NET or Visual C#. Second, MSIL code is compiled to native code. - Name any 2 of the 4 .NET authentification methods
ASP.NET, in conjunction with Microsoft Internet Information Services (IIS), can authenticate user credentials such as names and passwords using any of the following authentication methods:- Windows: Basic, digest, or Integrated Windows Authentication (NTLM or Kerberos).
- Microsoft Passport authentication
- Forms authentication
- Client Certificate authentication
- How do you turn off SessionState in the web.config file?
In the system.web section of web.config, you should locate the httpmodule tag and you simply disable session by doing a remove tag with attribute name set to session.<httpModules>
<remove name=”Session” />
</httpModules> - What is main difference between Global.asax and Web.Config?
ASP.NET uses the global.asax to establish any global objects that your Web application uses. The .asax extension denotes an application file rather than .aspx for a page file. Each ASP.NET application can contain at most one global.asax file. The file is compiled on the first page hit to your Web application. ASP.NET is also configured so that any attempts to browse to the global.asax page directly are rejected. However, you can specify application-wide settings in the web.config file. The web.config is an XML-formatted text file that resides in the Web site’s root directory. Through Web.config you can specify settings like custom 404 error pages, authentication and authorization settings for the Web site, compilation options for the ASP.NET Web pages, if tracing should be enabled, etc.
C# Questions and Answers – 08
- What’s the implicit name of the parameter that gets passed into the class’ set method?
Value, and it’s datatype depends on whatever variable we’re changing. - How do you inherit from a class in C#?
Place a colon and then the name of the base class. - Does C# support multiple inheritance?
No, use interfaces instead. - When you inherit a protected class-level variable, who is it available to?
Classes in the same namespace. - Are private class-level variables inherited?
Yes, but they are not accessible, so looking at it you can honestly say that they are not inherited. But they are. - Describe the accessibility modifier protected internal.
It’s available to derived classes and classes within the same Assembly (and naturally from the base class it’s declared in). - C# provides a default constructor for me. I write a constructor that takes a string as a parameter, but want to keep the no parameter one. How many constructors should I write?
Two. Once you write at least one constructor, C# cancels the freebie constructor, and now you have to write one yourself, even if there’s no implementation in it. - What’s the top .NET class that everything is derived from?
System.Object. - How’s method overriding different from overloading?
When overriding, you change the method behavior for a derived class. Overloading simply involves having a method with the same name within the class. - What does the keyword virtual mean in the method definition?
The method can be over-ridden. - Can you declare the override method static while the original method is non-static?
No, you can’t, the signature of the virtual method must remain the same, only the keyword virtual is changed to keyword override. - Can you override private virtual methods?
No, moreover, you cannot access private methods in inherited classes, have to be protected in the base class to allow any sort of access. - Can you prevent your class from being inherited and becoming a base class for some other classes?
Yes, that’s what keyword sealed in the class definition is for. The developer trying to derive from your class will get a message: cannot inherit from Sealed class WhateverBaseClassName. It’s the same concept as final class in Java. - Can you allow class to be inherited, but prevent the method from being over-ridden?
Yes, just leave the class public and make the method sealed. - What’s an abstract class?
A class that cannot be instantiated. A concept in C++ known as pure virtual method. A class that must be inherited and have the methods over-ridden. Essentially, it’s a blueprint for a class without any implementation. - When do you absolutely have to declare a class as abstract (as opposed to free-willed educated choice or decision based on UML diagram)?
When at least one of the methods in the class is abstract. When the class itself is inherited from an abstract class, but not all base abstract methods have been over-ridden. - What’s an interface class? It’s an abstract class with public abstract methods all of which must be implemented in the inherited classes.
- Why can’t you specify the accessibility modifier for methods inside the interface?
They all must be public. Therefore, to prevent you from getting the false impression that you have any freedom of choice, you are not allowed to specify any accessibility, it’s public by default. - Can you inherit multiple interfaces?
Yes, why not. - And if they have conflicting method names?
It’s up to you to implement the method inside your own class, so implementation is left entirely up to you. This might cause a problem on a higher-level scale if similarly named methods from different interfaces expect different data, but as far as compiler cares you’re okay. - What’s the difference between an interface and abstract class?
In the interface all methods must be abstract, in the abstract class some methods can be concrete. In the interface no accessibility modifiers are allowed, which is ok in abstract classes. - How can you overload a method?
Different parameter data types, different number of parameters, different order of parameters. - If a base class has a bunch of overloaded constructors, and an inherited class has another bunch of overloaded constructors, can you enforce a call from an inherited constructor to an arbitrary base constructor?
Yes, just place a colon, and then keyword base (parameter list to invoke the appropriate constructor) in the overloaded constructor definition inside the inherited class. - What’s the difference between System.String and System.StringBuilder classes?
System.String is immutable, System.StringBuilder was designed with the purpose of having a mutable string where a variety of operations can be performed. - Is it namespace class or class namespace?
The .NET class library is organized into namespaces. Each namespace contains a functionally related group of classes so natural namespace comes first.
Display Record
Add Record
Edit Record