Hi
I have a web form with a label on it. The content of that label is updated in response to some javascript on the client webpage.
Upon completion of some data entry, a button is clicked which adds that labels data (and others) to a gridview.
Basically this all works except that I can not retrieve thae updated value of the label. The grid addrow routine always finds the labels default value and writes that instead.
I assume this is a postback related issue so I created a hidden field and wrote the value to that also and then pull that for the grid write. Same problem...
How can I write a value to a label with javascript and then pull that value (server side) in asp.net (VB) for writing into the grid?
This code writes to the label and hidden field-
function jsCalcFrames() {
var DurFrames = calcDurFrames();
var sVal1 = document.getElementById('<%= lbl_Segment_SoM.ClientID %>').textContent;//.innerText; supposedly ie only
var SoMframes = ConvertToFrames(sVal1);
var EoMframes = ConvertFromFrames(DurFrames + SoMframes - 1);
// lbl_Segment_EoM.Text = EoMframes; //remove 1 as eom is before som
document.getElementById('<%= lbl_Segment_EoM.ClientID %>').textContent = EoMframes;
document.getElementById('<%= hidden_Segment_EoM.ClientID %>').textContent = EoMframes;
//write to hidden field for persistence
if (DurFrames > 0) {
Me.btnAppendSegment.Enabled = True;
}
}
This partial code is triggered by the forms append button -
Protected Sub btnAppendSegment_Click(ByVal sender As Object, ByVal e As EventArgs) Handles btnAppendSegment.Click
appendSegmentArray(segIndex)
end sub
Private Sub appendSegmentArray(ByVal _index As Integer)
If xmlCheck_SegTitle <> 14 Then
MsgBox("You must give a title to this segment!", MsgBoxStyle.OkOnly Or MsgBoxStyle.Exclamation, "Segment data error!")
Exit Sub
End If
Dim sValDur As String = Me.txt_Segment_Dur_H.Text + ":" + _
Me.txt_Segment_Dur_M.Text + ":" + _
Me.txt_Segment_Dur_S.Text + ":" + _
Me.txt_Segment_Dur_F.Text
dt = TryCast(ViewState("SegmentData"), DataTable)
dt.Rows.Add(CInt(Me.lbl_Segment_Number.Text), Me.txt_Segment_Title.Text, Me.lbl_Segment_SoM.Text, Me.hidden_Segment_EoM.Value, sValDur)
dt.Rows.Add(CInt(Me.lbl_Segment_Number.Text), Me.txt_Segment_Title.Text, Me.lbl_Segment_SoM.Text, Me.lbl_Segment_EoM.Text, sValDur) '+index
' ExecuteInsert(CInt(Me.lbl_Segment_Number.Text), Me.txt_Segment_Title.Text, Me.lbl_Segment_SoM.Text, Me.lbl_Segment_EoM.Text, sValDur)
ViewState.Add("SegmentData", dt)
dgvSegments.DataSource = dt
dgvSegments.DataBind() 'updates
'other code snipped off
This line writes the gride -
dt.Rows.Add(CInt(Me.lbl_Segment_Number.Text), Me.txt_Segment_Title.Text, Me.lbl_Segment_SoM.Text, Me.hidden_Segment_EoM.Value, sValDur)
Me.hidden_Segment_EoM.Value has the equiv label of Me.lbl_Segment_EoM.Text
In this function, Me.lbl_Segment_EoM.Text always has the forms initial value despite that value having changed in the client form.
I need to write the reality client value.
Any clues anyone?