我用 jquery sortable + C# 创建了一个列表,用户(客户端)可以订购:
protected override void OnInit(EventArgs e)
{
base.OnInit(e);
HtmlGenericControl ul = new HtmlGenericControl("ul");
ul.ID = "ID";
ul.ClientIdMode = Static;
HtmlGenericControl li_1 = new HtmlGenericControl("li");
li_1.ID = "segment";
li_1.InnerText = "server 1";
li_1.ClientIdMode = Static;
HtmlGenericControl li_2 = new HtmlGenericControl("li");
li_2.ID = "page";
li_2.InnerText = "server 1";
li_2.ClientIdMode = Static;
ul.Controls.Add(li_1);
ul.Controls.Add(li_2);
static.Controls.Add(ul);
}
服务器生成:
<div id="static" runat="server">
<ul id="ID">
<li id="segment">server 1</li>
<li id="page">server 2</li>
</ul>
</div>
客户端生成(修改):
<div id="static" runat="server">
<ul id="ID">
<li id="page">client 1</li>
<li id="segment">client 2</li>
</ul>
</div>
活动保存:
protected void btnSave_Click(object sender, EventArgs e)
{
HtmlGenericControl ul = Libreria.Global.FindControlRecursivo(this, "ID") as HtmlGenericControl;
foreach(HtmlGenericControl li in ul.Controls.OfType<HtmlGenericControl>())
{
// Always get html generated by server, first "segment" element and after "page" element
}
}
如果每次我在每次回发时生成动态代码,我总是得到服务器生成的代码,如果有效,那么列表是空的回发。=(
如何获取从服务器端生成的 html 代码修改客户端?
更新: 其他选项是使用带有 javascript 的WebMethods 发送 html:
document.getElementById("ID").innerHTML;
我无法处理元素是一个简单的字符串
HtmlGenericControl ul = new HtmlGenericControl();
ul.InnerHtml = stringHtml;
foreach(HtmlGenericControl li in ul.Controls.OfType<HtmlGenericControl>())
{
// any element
}