![](/img/trans.png)
[英]How do i get the text of a dynamically created label , when i click from anchor tag using javascript
[英]How do I get text of label when changed to server side?
我不嘗試回發但失敗時,試圖將標簽的文本分配給隱藏字段。 這就是我所做的。
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沒有更新。
label的值是date,每次我使用客戶端的日歷控件更改日期時,此值都會更新。 但是,標簽的值不會隨該值刷新。
<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元素:
我認為只有呈現為輸入控件和在客戶端更改的值的控件才會在viewstate上更新,因此,您唯一的選擇就是堅持使用隱藏字段。
您只需要采取其他方法即可。
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
當然,每次在日歷控件中更改日期時,您都不會將其回發到服務器。 您可以使用__doPostback() function.
從javascript回發到服務器__doPostback() function.
看到這個鏈接: __doPostback函數示例
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.