我正在尝试动态加载LinkButton
以触发回发事件,然后我会处理该事件。
我有Command
,CommandName
和CommandArgument
- 这看起来真的很有用.. 所以我开始搞砸了,但目前无法按要求工作。
链接在动态创建的表中呈现,这是生成它们的代码:
// The links are stored in Session since I was told that the objects need to remain intact across requests.
LinkButton GetEditCardLink(string card)
{
if (!IsPostBack)
{
TW("Creating Link for Card '" + card + "' and Placing in Session.", true);
LinkButton link = CreateEditLink(card);
Business.Session.Set<LinkButton>("LinkedCards_EditLink_" + card, link);
}
return Business.Session.Get<LinkButton>("LinkedCards_EditLink_" + card);
}
// Here the link itself is created, note the ID and Command details are set.
LinkButton CreateEditLink(string forCard)
{
TW("Setting Up Link for Card: " + forCard, true);
LinkButton rtn = new LinkButton();
rtn.ID = "Edit_" + forCard;
rtn.Text = Resources.Header("EditDetails");
rtn.CommandName = "Edit";
rtn.CommandArgument = forCard;
rtn.Command += new CommandEventHandler(RedirectToEdit);
rtn.Attributes["style"] = "display: block; text-align:center;";
return rtn;
}
// ... And the delegate I want called on PostBack..
void RedirectToEdit(object sender, CommandEventArgs e)
{
TW("RedirectToEdit Called:\r\nName: " + e.CommandName + "\r\nArgument: " + e.CommandArgument);
}
Trace确认LinkButtons被正确加载,并且只创建一次,所以理论上它们应该没问题,但是当我点击链接时,执行了一个PostBack,但RedirectToEdit
没有调用该方法?
感谢所有帮助!:)
笔记
哦,我想我应该提到TW
的只是一个实用方法Trace.Write/Warn
:)