【发布时间】:2012-10-29 20:41:45
【问题描述】:
在网络表单中,我有一个 jquery datepicker,它绑定到 ui 中的文本字段,而该文本字段又绑定到隐藏字段(asp 隐藏字段不是 html)
<div class="dateContainer">
<span class="fbSmallLabel">Start Date</span>
<input id="txtStartDate" class="datequeryterm" type="text" value="<%= ((HiddenField)Parent.FindControl("hdnStartDate")).Value %>" />
</div>
When a date is selected the hndfield is updated which then updates the value in the textbox
$("#btnApplyFilter").click(function () {
setFilterFields();
$.modal.close();
});
function setFilterFields() {
var startDate = $("#txtStartDate").val();
var endDate = $("#txtEndDate").val();
$("#hdnStartDate").val(startDate);
$("#hdnEndDate").val(endDate);
}
使用 firebug 或 IE 开发工具,我可以看到隐藏字段在 DOM 中已更新,但是当我从 webform 引用隐藏字段时,我得到一个 null "" 值。
protected void SetSearchFilterData()
{
DateTime dt;
string StartDate = hdnStartDate.Value;
string EndDate = hdnEndDate.Value;
if (DateTime.TryParse(StartDate, out dt))
{
srchRequest.DateRangeStart = DateTime.Parse(StartDate);
}
if (DateTime.TryParse(EndDate, out dt))
{
srchRequest.DateRangeEnd = DateTime.Parse(EndDate);
}
}
该方法有点基本,因为我试图明确地查看变量赋值发生了什么。 以前我是通过以下方式声明开始日期和结束日期
public string StartDate
{
get { return hdnStartDate.Value; }
set { hdnStartDate.Value = value; }
}
虽然这确实检测到该字段,但该值仍然为空。
任何建议将不胜感激
-干杯
【问题讨论】:
-
隐藏字段值能否在 pageLoad 上重置?
-
@JoshMein 不,这就是我的想法,但在查看并非如此的萤火虫时,我可以在应用它们后看到这些值并且它们没有被重置。但是,当在单击事件上从网络表单调用时,该值为 null,但仅针对日期。其他隐藏字段保留其值。
标签: jquery asp.net jquery-ui hidden-field