S
Scott McDaniel
The code below cannot locate the Textbox "tbDuration" in my ASP.NET 2.0 page.
<Ajax.AjaxMethod()> _
Public Function calcTimeSpan(ByVal StartTime As String, ByVal EndTime As String) As String
Dim dblTimeSpan As Double
Dim RtnVal As String
Dim tb As TextBox
Try
If StartTime.Length < 1 Or EndTime.Length < 1 Then
Return ""
Else
dblTimeSpan = DateAndTime.DateDiff(DateInterval.Minute, CDate(StartTime), CDate(EndTime))
RtnVal = Format(dblTimeSpan / 60, "###0.0")
tb = Me.FindControl("tbDuration")
If Not tb Is Nothing Then tb.Text = RtnVal
Return RtnVal
End If
Catch ex As Exception
Return ""
End Try
End Function
As you can see, this is an AJAX function, and I am not at all familiar with AJAX (I didn't write this, but have been
charged with maintaining it).
As you can see, the code is pretty simple, just date manipulation, which is working - I can pass input values into the
codeblock and the calc occurs, so RtnVal has a value (eg: 2.0, 3.2, etc)
This project does use MasterPages, and if I ViewSource the tb is referenced as such:
ctl00_ContentPlaceHolder1_tbDuration
I've tried that, but the code errors out as well. If I remove the Me.FindControl and try to set the value directly,
without using FindControl:
Me.tbDuration.Text = RtnVal
then VS errors and I get a System.NullReferenceException telling me there is no Object referenced (which I assume means
it can't find tbDuration).
The textbox does exist, and Intellisense shows it.
<Ajax.AjaxMethod()> _
Public Function calcTimeSpan(ByVal StartTime As String, ByVal EndTime As String) As String
Dim dblTimeSpan As Double
Dim RtnVal As String
Dim tb As TextBox
Try
If StartTime.Length < 1 Or EndTime.Length < 1 Then
Return ""
Else
dblTimeSpan = DateAndTime.DateDiff(DateInterval.Minute, CDate(StartTime), CDate(EndTime))
RtnVal = Format(dblTimeSpan / 60, "###0.0")
tb = Me.FindControl("tbDuration")
If Not tb Is Nothing Then tb.Text = RtnVal
Return RtnVal
End If
Catch ex As Exception
Return ""
End Try
End Function
As you can see, this is an AJAX function, and I am not at all familiar with AJAX (I didn't write this, but have been
charged with maintaining it).
As you can see, the code is pretty simple, just date manipulation, which is working - I can pass input values into the
codeblock and the calc occurs, so RtnVal has a value (eg: 2.0, 3.2, etc)
This project does use MasterPages, and if I ViewSource the tb is referenced as such:
ctl00_ContentPlaceHolder1_tbDuration
I've tried that, but the code errors out as well. If I remove the Me.FindControl and try to set the value directly,
without using FindControl:
Me.tbDuration.Text = RtnVal
then VS errors and I get a System.NullReferenceException telling me there is no Object referenced (which I assume means
it can't find tbDuration).
The textbox does exist, and Intellisense shows it.