Wednesday, March 9, 2011

How to remove dynamically created controls in ASP.Net

 Panel1.Controls.Remove(Panel1.FindControl("ControlName"));


http://msdn.microsoft.com/en-us/library/ms972975.aspx#usercontrols_topic7

Events sequence in ASP.NET WebForms

Events sequence in ASP.NET WebForms
MaterPage is a UserControl (Master page inherit from user control.)

Application: BeginRequest
Application: PreAuthenticateRequest
Application: AuthenticateRequest
Application: PostAuthenticateRequest
Application: PreAuthorizeRequest
Application: AuthorizeRequest
Application: PostAuthorizeRequest
Application: PreResolveRequestCache
Application: ResolveRequestCache
Application: PostResolveRequestCache
Application: PreMapRequestHandler
Page: Construct
Application: PostMapRequestHandler
Application: PreAcquireRequestState
Application: AcquireRequestState
Application: PostAcquireRequestState
Application: PreRequestHandlerExecute
Page: AddParsedSubObject
Page: CreateControlCollection
Page: AddedControl
Page: AddParsedSubObject
Page: AddedControl
Page: ResolveAdapter
Page: DeterminePostBackMode
Page: PreInit
Control: ResolveAdapter
Control: Init
Control: TrackViewState
Page: Init
Page: TrackViewState
Page: InitComplete
Page: LoadPageStateFromPersistenceMedium
Control: LoadViewState
Page: EnsureChildControls
Page: CreateChildControls
Page: PreLoad
Page: Load
Control: DataBind
Control: Load
Page: EnsureChildControls
Page: LoadComplete
Page: EnsureChildControls
Page: PreRender
Control: EnsureChildControls
Control: PreRender
Page: PreRenderComplete
Page: SaveViewState
Control: SaveViewState
Page: SaveViewState
Control: SaveViewState
Page: SavePageStateToPersistenceMedium
Page: SaveStateComplete
Page: CreateHtmlTextWriter
Page: RenderControl
Page: Render
Page: RenderChildren
Control: RenderControl
Page: VerifyRenderingInServerForm
Page: CreateHtmlTextWriter
Control: Unload
Control: Dispose
Page: Unload
Page: Dispose
Application: PostRequestHandlerExecute
Application: PreReleaseRequestState
Application: ReleaseRequestState
Application: PostReleaseRequestState
Application: PreUpdateRequestCache
Application: UpdateRequestCache
Application: PostUpdateRequestCache
Application: EndRequest
Application: PreSendRequestHeaders
Application: PreSendRequestContent

Tuesday, March 8, 2011

In ASP.NET URL rewriting, should use 301 Moved Permanently redirect instead of 302 for SEO

For 301, Search engines will accept this and page ranking is divided between old and new version of the page.

Permanent (301) redirection in ASP.NET
Response.Status = "301 Moved Permanently";
Response.AddHeader("Location", "/New-Page/");
Response.End();

Permanent redirection in ASP.NET 4.0
Response.RedirectPermanent("New-URL.aspx", true);

Entity Framework Database support list, MySQL, Oracle, Firebird, DB2

Full detail:
http://msdn.microsoft.com/en-us/data/dd363565.aspx

How to solve "There is already an open DataReader associated with this Command which must be closed first"

Add following section into database connection string in config file

MultipleActiveResultSets=True;