我创建了动态LinkButton,并将LinkButton的Click Trigger添加到UpdatePanel。
现在,当我第一次点击任何一个链接按钮触发器运行良好并显示我的选择whitout POSTBACK。之后,我点击其他LinkButton所有页面加载和POSTBACK运行,因此触发器不起作用! 问题是什么 ?请帮助!
protected void Page_Load(object sender, EventArgs e)
{
ShowAllCar();
}
public void ShowAllCar()
{
dsAraclarTableAdapters.tblAraclarTableAdapter _t=new dsAraclarTableAdapters.tblAraclarTableAdapter();
dsAraclar.tblAraclarDataTable _m =_t.GetData();
int i=0;
UpdatePanel1.Triggers.Clear();
pnlAraclar.Controls.Clear();
foreach (DataRow _row in _m.Rows)
{
LinkButton _linkbutton =new LinkButton();
i++;
_linkbutton.ID ="Option" + i.ToString();
_linkbutton.Text = "<img src='" + _row["Resim"].ToString() + "' border='0'/> <b>" + _row["Marka"].ToString() + " " + _row["Model"].ToString() + "</b><br/>" + _row["Ozellikler"].ToString() + " : " + _row["KisFiyat"].ToString() + ":" + _row["YazFiyat"].ToString();
_linkbutton.CssClass="ContextMenuItem";
_linkbutton.PostBackUrl = "";
_linkbutton.Click +=new EventHandler(OnCarSelect);
pnlAraclar.Controls.Add(_linkbutton);
AsyncPostBackTrigger _trigger = new AsyncPostBackTrigger();
_trigger.ControlID = _linkbutton.ID;
_trigger.EventName = "Click";
UpdatePanel1.Triggers.Add(_trigger);
}
}
protected void OnCarSelect(object sender, EventArgs e)
{
lblSelection.Text = "You selected <b>" + ((LinkButton)sender).Text + "</b>.";
}
答案 0 :(得分:2)