3 Replies - 1010 Views - Last Post: 22 June 2013 - 06:23 PM Rate Topic: -----

#1 jace75  Icon User is offline

  • New D.I.C Head

Reputation: 2
  • View blog
  • Posts: 31
  • Joined: 11-June 13

Control with ID "MyID" could not be found for Trigger in Updat

Posted 22 June 2013 - 04:24 PM

In my mind, this is how one would logically insert a control dynamically into an UpdatePanel object using C#.net...

public void PageInit(){
     AddMyControl();
}
public void AddMyControl(){
     LinkButton MyControl = new LinkButton();
     MyControl.Text = "Hello World";
     MyControl.ID = "MyID";
     MyControl.Click = new EventHandler(MyClickEvent);
     
     AsyncPostBackTrigger trigger = new AsyncPostBackTrigger();
     trigger.ControlID = MyControl.ID;
     trigger.EventName = "Click";
     MyPanel.Triggers.Add(trigger);

     TableCell cell = new TableCell();
     cell.Controls.Add(MyControl);
     TableRow row = new TableRow();
     row.Cells.Add(cell);
     MyTable.Rows.Add(row);
}




The error says the control could not be found. That makes me ask the question: where on earth is it looking? I mean, really? I put it right there! :'(

Is This A Good Question/Topic? 0
  • +

Replies To: Control with ID "MyID" could not be found for Trigger in Updat

#2 andrewsw  Icon User is online

  • Fire giant boob nipple gun!
  • member icon

Reputation: 3325
  • View blog
  • Posts: 11,243
  • Joined: 12-December 12

Re: Control with ID "MyID" could not be found for Trigger in Updat

Posted 22 June 2013 - 05:04 PM

At what line does it say the control could not be found?
Was This Post Helpful? 0
  • +
  • -

#3 jace75  Icon User is offline

  • New D.I.C Head

Reputation: 2
  • View blog
  • Posts: 31
  • Joined: 11-June 13

Re: Control with ID "MyID" could not be found for Trigger in Updat

Posted 22 June 2013 - 05:08 PM

The error occurs on page_load. My ScriptManager object attempts to register the dynamically added trigger, but it cannot locate the control I've assigned it, for some reason. I've searched dozens of forums for the answer to this problem, but no one seems to posses the solution...
Was This Post Helpful? 0
  • +
  • -

#4 jace75  Icon User is offline

  • New D.I.C Head

Reputation: 2
  • View blog
  • Posts: 31
  • Joined: 11-June 13

Re: Control with ID "MyID" could not be found for Trigger in Updat

Posted 22 June 2013 - 06:23 PM

Solved!

The reason my control was not being recognized: I was adding the control as a trigger before adding it to my table. Apparently, the control itself cannot be added to "the list" until placed inside of a container. It kind of makes sense. I wouldn't instantiate a string object by setting it to another string that had not yet been instantiated. It's kind of the same principle. The UpdatePanel's Trigger object doesn't need to know my Control object, it just needs to reference it's address inside of the page. Until given that address, Trigger can't even know the control exists.

Happy coding!
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1