Skip to content

Instantly share code, notes, and snippets.

@dingjing
dingjing / CallSaveData.aspx.cs
Created February 3, 2012 20:50
Call SaveData()
try {
DbUtils.StartTransaction();
if (!this.IsPageRefresh) {
this.SaveData();
}
this.CommitTransaction(sender);
} catch (Exception ex) {
// Upon error, rollback the transaction
this.RollBackTransaction(sender);
this.ErrorOnPage = true;
@dingjing
dingjing / InterceptPB.aspx.cs
Created February 3, 2012 20:54
Intercept Postbacks
public partial class EditProductsTable
: BaseApplicationPage
// Code-behind class for the EditProductsTable page.
// Place your customizations in Section 1. Do not modify Section 2.
{
#region "Section 1: Place your customizations here."
HashSet<string> AutoSaveCtrlIDs = new HashSet<string>();
@dingjing
dingjing / InterceptPBDumb.aspx.cs
Created February 12, 2012 03:20
Intercept postbacks brute-force
public partial class EditProductsTable2
: BaseApplicationPage
// Code-behind class for the EditProductsTable2 page.
// Place your customizations in Section 1. Do not modify Section 2.
{
#region "Section 1: Place your customizations here."
public EditProductsTable2() {
this.Initialize();
@dingjing
dingjing / savebutton_click.cs
Created June 2, 2012 22:23
Cannot insert in SaveButton_Click
public void SaveButton_Click(object sender, EventArgs args) {
// Cannot insert here. Data not saved yet.
// Click handler for SaveButton.
// Customize by adding code before the call or replace the call to the Base function with your own code.
SaveButton_Click_Base(sender, args);
// NOTE: If the Base function redirects to another page, any code here will not be executed.
// Cannot insert here either.
// If data is saved successfully, the page is redirected. This code won't be executed.
@dingjing
dingjing / Cut_and_Paste.cs
Created June 25, 2012 05:08
Cut-and-Paste SaveButton_Click_Base
public void SaveButton_Click(object sender, EventArgs args) {
bool shouldRedirect = true;
string TargetKey = null;
string DFKA = TargetKey;
string id = DFKA;
string value = id;
try {
// Enclose all database retrieval/update code within a Transaction boundary
@dingjing
dingjing / Override_CommitTransaction.cs
Created June 25, 2012 05:17
Override CommitTransaction
public override void CommitTransaction(object sender) {
base.CommitTransaction(sender);
// Your custom code here.
}
@dingjing
dingjing / FindControl
Created November 8, 2012 05:29
FindControl Snipprt
TextBox CustomerID = MiscUtils.FindControlRecursively(Page, "CustomerID") as TextBox;
string idValue = CustomerID.Text;
@dingjing
dingjing / PageExt.cs
Created November 9, 2012 05:17
Reuse code snippet with page extension method
#region "Section 1: Place your customizations here."
public static class PageExt {
public static string CustomerID(this Page page) {
return (MiscUtils.FindControlRecursively(page, "CustomerID") as TextBox).Text;
}
}
@dingjing
dingjing / UsePageExt.cs
Created November 9, 2012 05:28
Use page extension snippet
string idValue = Page.CustomerID();
@dingjing
dingjing / RandonAMP.cs
Created November 9, 2012 15:26
Pick Random AMP member
var ampMembers = MemberTable.GetRecords("AMP = 1");
int random = new Random(DateTime.Now.Ticks).Next(ampMembers.Length);
this.DataSource = ampMembers[random];