Solve new page flicker in AJAX
Want to stop flickering when going from one page to another in AJAX?
Put the following code in your head section:
<head runat="server"> <meta http-equiv="Page-Enter" content="BlendTrans(Duration=.05)" /> <meta http-equiv="Page-Exit" content="BlendTrans(Duration=.05,Translation=0)" /> </head>
For more details about these meta settings, go to http://www.aim-higher.net/meta-transitions.asp.
ASP.NET User Control events tamed through Page_PreRenderComplete
Something that has been bothering me for a really long time is now under control thanks to a blog post in the .NET Geek’s Blog entry on Understanding the Page Life Cycle in ASP.NET. In a nutshell, here is the issue. I prefer to create user controls that wrap standard .NET controls and then put role enabled and other code into the controls. That code determines if the control makes it self visible or disabled along with some other nice to haves.
The problem is that when a page first draws and fires off its events, the user control events follow, and if I come into the page wanting a button to be disabled in certian instances, the user controls resolve their states after the page. So if I have a button in a user control and expose its Enabled property through a get/set variable, I can never make it stick when the page first draws.
In the source code below, I am using the Page_PreRenderComplete event to test for page state and call an appropriate method. In this case the PrepUIforAdd is called and it disables a number of buttons as well other things. If I called PrepUIforAdd in the Page_PreRender event, the buttons would never stay disabled. But calling it in the Page_PreRenderComplete event will result in the outcome I want when the page displays.
/// <summary> /// PreRender is complete /// </summary> /// <param name="sender"></param> /// <param name="e"></param> protected void Page_PreRenderComplete( object sender, EventArgs e ) { if ( !Page.IsPostBack ) { ucErrorMessage.Clear(); switch ( this.CurrentPageState ) { case PageState.Add: { PrepUIforAdd(); break; } case PageState.Edit: { PopulatePersonInfo(); PopulateLinkedRoles(); PopulateUnlinkedRoles(); break; } } this.ManagePersonTabContainer.ActiveTabIndex = 0; } } /// <summary> /// Preps UI for adding a person /// </summary> private void PrepUIforAdd() { this.txtPersonID.Text = (PersonIDConstant.Everybody.ToInt()).ToString(); this.txtLastName.Text = string.Empty; this.txtFirstName.Text = string.Empty; this.txtLogin.Text = string.Empty; this.txtPassword.Text = string.Empty; this.txtInceptionDate.Text = string.Empty; this.txtLastModifiedDate.Text = string.Empty; this.txtLastModifiedByPersonName.Text = string.Empty; this.ddActive.YesNoID = 1; this.ddDeleted.YesNoID = 0; lbRolesAvailable.Clear(); lbRolesSelected.Clear(); this.bDelete.Enabled = false; this.bNew.Enabled = false; this.bResetPassword.Enabled = false; this.bRoleLink.Enabled = false; this.bRoleUnlink.Enabled = false; ddEmailType.Clear(); List<EmailCollection> dt = GetCachedEmailList(); if ( this.ErrorLevel == Status.Success ) { ddEmailType.DataSource = dt; ddEmailType.DataTextField = "EmailTypeName"; ddEmailType.DataValueField = "EmailTypeID"; ddEmailType.DataBind(); } this.txtEmail.Text = GetCachedEmailAddress( PersonIDConstant.Everybody.ToInt(), ddEmailType ); }
Recent Comments