Hi!
I have a custom control on my web form:
<form id="form" runat="server">
<clc:CustomList
ID="myList"
runat="server"
AddButtonText="add"
DeleteButtonText="del"
MoveUpButtonText="up"
MoveDownButtonText="down"/>
<div id="test" runat="server"></div>
</form>
I need to get to this control from a static WebMethod. I get the Page object from current HttpContext, but it seems this page object has no contorls (controls count is 0).
[WebMethod]
public static List<CustomListControl.IListItem> GetListItems()
{
Page page = HttpContext.Current.Handler as Page;
Control control = null;
if (page != null)
{
control = FindControlRecursive(page, "myList");
}
return null;
}
private static Control FindControlRecursive(Control root, string id)
{
if (root.ID == id)
{
return root;
}
foreach (Control c in root.Controls)
{
Control t = FindControlRecursive(c, id);
if (t != null)
{
return t;
}
}
return null;
}
Any idea why or how to get to my control? Thanks!