ASP Cant Find my Textbox Control

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.
 
S

Steven Cheng[MSFT]

Hello Scott,

Thank you for posting in the ASPNET newsgroup.

From your description, I understand you're encountering some problem when
developing an ASP.NET web page that use some AJAX components, correct?

Based on my research, the AJAX component you're using is a 3rd party AJAX
framework mentioned below:

http://msdn.microsoft.com/library/en-us/dnaspp/html/ASPNetSpicedAjax.asp?fra
me=true

And I've also checked its workspace and the document, it seems that this
AJAX framework is using a custom httphandler to processing those ajax
callback from cilent-side script to server. And this custom httphandler(not
the original ASP.NET page's page handler) will help locate the certain ajax
method from the certain page class and call it. Therefore, as for such AJAX
method, it can not access the original ASP.NET page's page model or control
structure(they're not populated in the AJAX httphandler). Actually, such
AJAX method is used to perform some helper functions(such as server-side
calculation , or accesing some server-side database...). As for UI related
manipulation in AJAX environment, it is better to do some at client-side
directly on those cilent-side html elements through scripts.

Regards,

Steven Cheng
Microsoft Online Community Support


==================================================

When responding to posts, please "Reply to Group" via your newsreader so
that others may learn and benefit from your issue.

==================================================


This posting is provided "AS IS" with no warranties, and confers no rights.



Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)
 
S

Steven Cheng[MSFT]

Hi Scott,

How are you doing in this issue, have you got any progress or does the
information in my last reply helps you a little? If there is anything else
we can help, please feel free to post here.

Regards,

Steven Cheng
Microsoft MSDN Online Support Lead


==================================================

When responding to posts, please "Reply to Group" via your newsreader so
that others may learn and benefit from your issue.

==================================================


This posting is provided "AS IS" with no warranties, and confers no rights.



Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,756
Messages
2,569,535
Members
45,008
Latest member
obedient dusk

Latest Threads

Top