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
}