I have a list which the elements can be reordered or dragged out of the list by JQuery sortable function. When the user press save, raises a postback. I need to capture the list, get the ids still inside the list and by order they come int the html. My approach is add the hidden field inside each ul tag, to store the id of the list item, like this
<ul>
<li>Item1 <input id="itemID" type="hidden" value="1"></li>
<li>Item2 <input id="itemID" type="hidden" value="2"></li>
...
</ul>
For that i subclass WebControl
. At RenderContents
method, i render the html as posted.
The problem is how to access the control children on the postback call.
Because the JavaScript change the list, the Viewstate
is useless.
The property Controls always come empty. Can't find a way to force the parse of the Innerhtml
or even get the Innerhtml
.
What am i missing here?
UPDATE: To clarify, the html posted above is produced by the subclass of webcontrol. Below the code of the server control that i named as MyListControl:
[ToolboxData("<{0}:ServerControl1 runat=server></{0}:ServerControl1>")]
public class MyListControl : WebControl {
[Bindable(true)]
[Category("Appearance")]
[DefaultValue("")]
[Localizable(true)]
public List<String> Itens;
protected override void RenderContents(HtmlTextWriter output)
{
var ul = new HtmlGenericControl("ul");
int order = 0;
if (Itens != null)
foreach (var liText in Itens)
{
var li = new HtmlGenericControl("li");
li.InnerText = liText;
ul.Controls.Add(li);
var input = new HtmlInputHidden() { ID = "Order", Value = order.ToString() };
li.Controls.Add(input);
order++;
}
Controls.Add(ul);
ul.RenderControl(output);
}
}
Because the html is not parsed on post FindControl method can't find anything also.