How would you create a new html li
element dynamically in the code behind (server side)?
How would you access an li
in an existing ul
element on the server side?
I need to FindControl get all li
items and then add new li
item.
Update
I'm using jquery ajax to access server side, so I must use static WebMethod. FindControl is non/static method.
<script type="text/javascript">
$(function(){
$("#sortable").sortable();
$("#sortable").disableSelection();
});
This is jQuery Ajax Call
$(document).ready(function() {
// Add the page method call as an onclick handler for the div.
$("#Result").click(function() {
$.ajax({
type: "POST",
url: "DraggableTest.aspx/SomeMethod",
data: "{}",
contentType: "application/json; charset=utf-8",
dataType: "json",
success: function(msg) {
// Replace the div's content with the page method's return.
$("#Result").text(msg.d);
}
});
});
});
This is CodeBehind
[WebMethod]
public static string SomeMethod()
{
// using System.Web.UI.HtmlControls;
HtmlGenericControl ul = FindControl("sortable") as HtmlGenericControl;
if (ul != null)
{
foreach (HtmlControl c in ul.Controls)
{
if (c.TagName.ToLower() == "li")
{
// Processing here
}
}
}
}