コンテキスト:各ページに2つのテーブルを作成する必要がある4ページを作成する必要があります。各テーブルは同じ構造を持ち、変更されるのはロードされるデータだけです。イベントでデリゲートを使用する
私はページ上で6つの類似したテーブルを実行しなければならない別のページと同様のことをしました。私はdifferentsデータを与える関数に代理人を使用し、私は自分のTableInit関数に必要な関数を渡します。うまくいく! :)
しかし、今私はすべての機能を貼り付けなくても、テーブルをセーバルページに置くことができるようにすべてのテーブルジェネレータ機能を置く静的クラスを考えることにしています。
問題は、テーブルのどこかにボタンがあり、このボタンのpage.aspxにあるイベントを修正していることです。私が別の静的クラスに自分の関数を置くと、私は自分のイベントを渡す方法を見つけることができません。
私はここにページ内のすべての項目を貼り付けています。そのページからテーブルジェネレータ機能をどのように分離していますか?
namespace Pointage
{
public delegate List<M_FICHE> delOnGetRecent(M_USER_POINTAGE p_user);
public partial class _Default : Page
{
protected void Page_Load(object sender, EventArgs e)
{
tableInit(this.recentFicheDataTableHead, this.recentFicheDataTableBody, M_FICHE.getFiveRecentUserFiche);
tableInit(this.recentFicheNeededCorrectDataTableHead, this.recentFicheNeededCorrectDataTableBody, M_FICHE.getFiveRecentUserFicheWithNeededCorrections);
tableInit(this.recentFicheNeedApprovalDataTableHead, this.recentFicheNeedApprovalDataTableBody, M_FICHE.getFiveRecentUserFicheWithNeededApproval);
tableInit(this.recentFicheNeededValidDataTableHead, this.recentFicheNeededValidDataTableBody, M_FICHE.getFiveRecentUserFicheWithNeededValidation);
tableInit(this.recentErrorFicheDataTableHead, this.recentErrorFicheDataTableBody, M_FICHE.getFiveRecentErrorFiche);
langInit();
}
//procédure d'initialisation des différents label prenant compte de la langue
private void langInit()
{
// Useless for this problem
}
/// <summary> Table init. </summary>
///
/// <remarks> G 0669144, 26/10/2016. </remarks>
///
/// <param name="p_head"> The head. </param>
/// <param name="p_body"> The body. </param>
/// <param name="p_delOnGetRecent"> The delete on get recent method from M_FICHE. </param>
/// <param name="p_link"> The link. </param>
private void tableInit(HtmlGenericControl p_head, HtmlGenericControl p_body, delOnGetRecent p_delOnGetRecent)
{
List<M_FICHE> _listFiche = p_delOnGetRecent(new M_USER_POINTAGE(Convert.ToInt32(Session["id"])));
if (_listFiche.Count == 0)
{
p_head.Controls.Clear();
HtmlTableRow _row = new HtmlTableRow();
HtmlTableCell _cell = new HtmlTableCell();
_cell.InnerText = Resource.NO_RECENT_FICHE;
_row.Controls.Add(_cell);
p_head.Controls.Add(_row);
}
else
{
// HIDED CODE : creating thead code
p_body.Controls.Clear();
foreach (M_FICHE fiche in _listFiche)
{
//Création de la ligne du tableau
HtmlTableRow _row = new HtmlTableRow();
//Création de chaque cellules
HtmlTableCell cell = new HtmlTableCell();
M_USER_POINTAGE _user = M_USER_POINTAGE.getUserFromSGID(fiche.USER_SGID);
cell.InnerText = String.Format("{0}. {1}", _user.NAME[0], _user.FIRSTNAME);
_row.Controls.Add(cell);
//Cellule data
HtmlTableCell cell2 = new HtmlTableCell();
cell2.InnerText = fiche.DATE_CREATE.ToShortDateString();
_row.Controls.Add(cell2);
//Cellule status
HtmlTableCell cell3 = new HtmlTableCell();
cell3.InnerText = StatusManager.getRessource((STATUS)fiche.STATUT);
_row.Controls.Add(cell3);
//cellule action
HtmlTableCell cell4 = new HtmlTableCell();
//Ajout du bouton
HtmlButton _button = new HtmlButton();
_button.Attributes.Add("class", "btn btn-default");
_button.InnerText = Resource.BTN_ACCESS_CARD;
// HERE IS THE PROBLEM
_button.ServerClick += _buttonAccess_ServerClick;
//bind on button
cell4.Controls.Add(_button);
_row.Controls.Add(cell4);
p_body.Controls.Add(_row);
}
}
}
private void _buttonAccess_ServerClick(object sender, EventArgs e)
{
}
それは私が考えていたことではありませんが、それはまた非常に興味深いです、ありがとう:)私はそれを見ます:) –