Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/290.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/78.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# 使用jquery在asp.net winforms中设置隐藏字段时出现问题_C#_Jquery_Winforms - Fatal编程技术网

C# 使用jquery在asp.net winforms中设置隐藏字段时出现问题

C# 使用jquery在asp.net winforms中设置隐藏字段时出现问题,c#,jquery,winforms,C#,Jquery,Winforms,我有一些代码来设置隐藏字段的值,这样我可以在代码隐藏中访问它,但在代码隐藏中该值始终为空。正在设置effectiveDate的值,但我看起来不像是正在设置隐藏字段属性value <input id="appEffectiveDate" type="text" /> <label id="effectiveDateLabel" for="appEffectiveDate">App Effective Date</label> <script src="ht

我有一些代码来设置隐藏字段的值,这样我可以在代码隐藏中访问它,但在代码隐藏中该值始终为空。正在设置
effectiveDate
的值,但我看起来不像是正在设置隐藏字段属性
value

<input id="appEffectiveDate" type="text" />
<label id="effectiveDateLabel" for="appEffectiveDate">App Effective Date</label>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/2.1.3/jquery.min.js"></script>
<asp:HiddenField ID="appEffectiveDateToSetForUserRole" runat="server" Value="" Visible="false" />
<script>
$(function () {
    var SelectedDates = {};
    $('#appEffectiveDate').datepicker({
        beforeShowDay: function (date) {
            var Highlight = SelectedDates[date];
            if (Highlight) {
                return [true, "Highlighted", Highlight];
            }
            else {
                return [true, '', ''];
            }
        }
    });
    $("#effectiveDateLabel").hide();
    $("#appEffectiveDate").hide();
    $('input[value="85"]').click(function () {
        if($(this).is(':checked'))
        {
            $("#effectiveDateLabel").show();
            $("#appEffectiveDate").show();
        }
    });
    $("#appEffectiveDate").change(function () {
        var effectiveDate = $("#appEffectiveDate").val();
        $(":asp(appEffectiveDateToSetForUserRole)").prop('value', effectiveDate);
    });
});
</script> 

如果将
Visible
设置为
false
,则ASP.NET根本不会在标记中呈现该控件,这意味着jQuery将无法找到它,因为它不存在。只需移除可见=假零件。它会隐藏起来的

if (!string.IsNullOrEmpty(appEffectiveDateToSetForUserRole.Value))
{
    // this is never called because .Value is empty
}