views:

267

answers:

1

Hi, I create dynamic LinkButton and I add LinkButton's Click Trigger to UpdatePanel.

Now, When I first click to any one of link button trigger is runing good and show my select whitout POSTBACK. After That, I click other LinkButton All Page Loading and POSTBACK running so Trigger Does Not Work! What is the problem ? Please Help!

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>.";
}
+2  A: 

You need to add the controls back to the control tree earlier in the page life cycle:

PreInit
Use this event for the following:
...
* Create or re-create dynamic controls.
...

ASP.NET Page Life Cycle Overview

rick schott