Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/html/84.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 在代码隐藏中获取li标记的值_C#_Html_Asp.net_.net_Webforms - Fatal编程技术网

C# 在代码隐藏中获取li标记的值

C# 在代码隐藏中获取li标记的值,c#,html,asp.net,.net,webforms,C#,Html,Asp.net,.net,Webforms,我有一个aspx视图,其中有以下代码片段: 这是 我需要获取代码隐藏中metiers元素内的所有li标记值 因此: 我该怎么做 最好的做法是什么 我没有足够的上下文来给你一个确切的解决方案,但我认为你所寻找的应该是这样的: <input type="hidden" name="ListVals" id="listVals" runat="server" /> <script type="text/javascript"> function SetLis

我有一个aspx视图,其中有以下代码片段:


    这是
我需要获取代码隐藏中
metiers
元素内的所有li标记值 因此:

  • 我该怎么做
  • 最好的做法是什么

我没有足够的上下文来给你一个确切的解决方案,但我认为你所寻找的应该是这样的:

<input type="hidden" name="ListVals" id="listVals" runat="server" />

<script type="text/javascript">
    function SetListVals(){
         var listVals = $('#metiers').children().html();

        $('#listVals').val(encodeURIComponent(listVals));
    }
</script>

函数SetListVals(){
var listVals=$('#metiers').children().html();
$('#listVals').val(encodeURIComponent(listVals));
}

在发布页面之前调用SetListvals(),然后检查listVals控件的值。您需要取消对其值的编码。

我认为您有两种选择,将
runnat=server
和id设置为
li
,然后在codebehind(简易方式)或Jquery Ajax上对值进行编码。您可以解释第二种方式吗,因为第一个与我的案例不匹配,因为我通过脚本jquery动态添加li标记,并且我不需要重新构建页面