For this project I am dynamically adding linkbuttons to a form that will update two seperate updatepanel's in my asp.net webform. Everything works fine, except the link buttons do a full postback as opposed to an asyncpostback. I am trying to set up some triggers on my link buttons as their being added to the page, but when I run the page I get the dreaded "Object reference not set to an instance of an object" error. Here is the code for the method that builds and adds the triggers to my form. The control causing the error is noted below, and It's the first result of my query. Any help would be awesome!
protected void loadRooms() { DataView dv = (DataView)srcGetRms.Select(DataSourceSelectArguments.Empty); UpdatePanel up1 = Page.FindControl("up1") as UpdatePanel; UpdatePanel up2 = Page.FindControl("up1") as UpdatePanel; int cnt = dv.Table.Rows.Count; string[,] idlist = new string[4, 1]; string s; string num; for (int n = 0; n < cnt; n++) { for (int i = 1; i < 5; i++) { int rn; if (dv.Table.Rows[n][3] != null) { rn = (int)dv.Table.Rows[n][3]; } else { rn = 0; } if (i == rn) { s = Hasher.DecryptString((string)dv.Table.Rows[n][1]) + "<br />" + Hasher.DecryptString((string)dv.Table.Rows[n][2]); TableCell c = tblRooms.FindControl("tc" + i) as TableCell; num = Convert.ToString((int)dv.Table.Rows[n][0]); switch(i) { case 1: LinkButton lb1 = new LinkButton(); lb1.Text = s; lb1.CssClass="lb"; lb1.Attributes.Add("id", "1"); lb1.Click +=new EventHandler(getData); c.Controls.Add(lb1); hd1.Text = num; AsyncPostBackTrigger trig = new AsyncPostBackTrigger(); trig.ControlID = "1"; trig.EventName = "Click"; up1.Triggers.Add(trig); up2.Triggers.Add(trig); break; case 2: LinkButton lb2 = new LinkButton(); lb2.Text = s; lb2.CssClass="lb"; lb2.Attributes.Add("id", "2"); lb2.Click +=new EventHandler(getData); c.Controls.Add(lb2); hd2.Text = num; AsyncPostBackTrigger trig2 = new AsyncPostBackTrigger(); trig2.ControlID = "2"; trig2.EventName = "Click"; up1.Triggers.Add(trig2); up2.Triggers.Add(trig2); break; case 3: LinkButton lb3 = new LinkButton(); lb3.Text = s; lb3.CssClass="lb"; lb3.Attributes.Add("id", "3"); lb3.Click +=new EventHandler(getData); c.Controls.Add(lb3); hd3.Text = num; AsyncPostBackTrigger trig3 = new AsyncPostBackTrigger(); trig3.ControlID = "3"; trig3.EventName = "Click"; up1.Triggers.Add(trig3); up2.Triggers.Add(trig3); break; case 4: LinkButton lb4 = new LinkButton(); lb4.Text = s; lb4.CssClass = "lb"; lb4.Attributes.Add("id", "4"); lb4.Click +=new EventHandler(getData); c.Controls.Add(lb4); hd4.Text = num; AsyncPostBackTrigger trig4 = new AsyncPostBackTrigger(); trig4.ControlID = "4"; trig4.EventName = "Click"; up1.Triggers.Add(trig4);//This is the control that causes the error. up2.Triggers.Add(trig4); break; } } } } }