我试图在不回发时将标签的文本分配给隐藏字段,但失败了。这就是我所做的。
If Not IsPostBack Then
Dim structPayperiod As strcPayperiodDet
structPayperiod = objTimeSystem.getCurrentPayPeriod()
hdnPayperiodseq.Value = structPayperiod.Payperiodid
hdnPayPeriodStartDt.Value = structPayperiod.startdate.ToString
lblPayPeriodStartDt.Text = structPayperiod.startdate
displayPayrollIdOrgs(objTimeSystem.getPayrollIDOrgs())
grd_Employees.Visible = False
RptErrorsMessages.DataSource = objTimeSystem.getErrorMessages()
RptErrorsMessages.DataBind()
Else
hdnPayPeriodStartDt.Value = lblPayPeriodStartDt.Text.ToString
End If
问题出现在 else 子句中,其中该值未使用新标签值进行更新。 lblPayPeriodStartDt.Text 未更新。
标签的值是日期,每次我使用客户端的日历控件更改日期时它都会更新。但是,标签的值不会用该值刷新。
<asp:Label ID="lblPayPeriodStartDt" runat="server"></asp:Label>
<img src="../Images/calendar.gif" class="clsCursorHand" alt="" title="Select Pay Period"
onclick="Javascript:PayPeriodsPayroll('<%=lblPayPeriodStartDt.ClientId %>',event);"/>
你不会得到的价值<asp:Label
您在客户端修改了后面的代码。如果我是正确的,ASP.NET 标签在客户端呈现为 span 元素:
我认为只有渲染为输入控件的控件和在客户端更改的值才会在视图状态上更新,因此您唯一的办法就是坚持隐藏字段。
你只需要反其道而行之即可。
1.将隐藏字段传递给js函数并在js函数中更新客户端隐藏字段的值PayPeriodsPayroll
像下面这样
function PayPeriodsPayroll (hdnObj)
{
var hdnPayPeriod = document.getElementById(hdnObj);
hdnPayPeriod.val('the value you want to set');
}
然后在你的页面加载中
If Not IsPostBack Then
....
Else
// update label with the hidden field value if you need it
lblPayPeriodStartDt.Text = hdnPayPeriodStartDt.Value
End If
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)