Created
December 27, 2012 21:18
-
-
Save DTTerastar/4392065 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class EnsureDataBound : Control | |
{ | |
private int _count; | |
public bool AllowMultiple { get; set; } | |
public bool EveryPostBack { get; set; } | |
public When When { get; set; } | |
public override void DataBind() | |
{ | |
if (!AllowMultiple && _count > 0) return; | |
_count++; | |
base.DataBind(); | |
} | |
public void ReDataBind() | |
{ | |
_count++; | |
base.DataBind(); | |
} | |
protected override void OnInit(EventArgs e) | |
{ | |
if (When == When.Init && (EveryPostBack || !Page.IsPostBack)) DataBind(); | |
base.OnInit(e); | |
} | |
protected override void OnLoad(EventArgs e) | |
{ | |
if (When == When.Load && (EveryPostBack || !Page.IsPostBack)) DataBind(); | |
base.OnLoad(e); | |
} | |
protected override void OnPreRender(EventArgs e) | |
{ | |
if (When == When.PreRender && (EveryPostBack || !Page.IsPostBack)) DataBind(); | |
base.OnPreRender(e); | |
} | |
} | |
public enum When | |
{ | |
Load, | |
Init, | |
PreRender | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment