簡體   English   中英

使用jquery在asp.net winforms中設置隱藏字段的問題

[英]Issue with setting hidden field in asp.net winforms using jquery

我有一些代碼來設置隱藏字段的值,所以我可以在后面的代碼中訪問它,但后面的代碼中的值總是為空。 正在設置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> 

在后面的代碼中隱藏字段的值為空:

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

如果Visible設置為false ,則ASP.NET中的標記根本不會呈現該控件,這意味着jQuery將無法找到它,因為它不存在。 只需刪除visible = false部分即可。 它會隱藏起來。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM