This is a migrated thread and some comments may be shown as answers.

Findcontrol RadnumericTextbox returns NULL

1 Answer 140 Views
Input
This is a migrated thread and some comments may be shown as answers.
Michael Kovac
Top achievements
Rank 1
Michael Kovac asked on 03 Jun 2009, 05:29 PM
Hi,
I have a page with a master page. This page has an HTML table and inside that table (no runat server! tag for the table) I have a bunch of RadnumericTextbox controls named tbx1, tbx2, through tbxn.
I want to iterate through these, but when I use the findcontrol method, I get an "Object Reference not set to an instance of an object" error. So i tried to get the value of just one named "tbx1" - still getting the rror
Here is the code I use to test with one control:

asp page:

 

<

 

telerik:RadNumericTextBox ID="tbx1" Runat="server"

 

 

Culture="English (United States)" DataType="System.Int16" MaxValue="400"

 

 

MinValue="0" ShowSpinButtons="True" Width="35px">

 

 

 

 

 

<NumberFormat DecimalDigits="0" />

 

 

 

 

 

</telerik:RadNumericTextBox>

 

 

 

Code behind:
Function CollectAnswer() as string
Dim

 

strResult As String = ""

 

 

Dim tbox As RadNumericTextBox

 

tbox = CType(Page.FindControl("tbx1"), RadNumericTextBox)

 

 

 

strResult = tbox.Text

 

 

Return strResult

 

End Function

I have also tried

tbox = Me.FindControl("tbx1") as the third line, same results

 


with the same results.
I get no errors in VS.

Help?

1 Answer, 1 is accepted

Sort by
0
Shinu
Top achievements
Rank 2
answered on 04 Jun 2009, 01:05 PM
Hi Michael,

Try the following code for accessing the RadNumericTextBox placed in master page.

VB:
 
Public Function CollectAnswer() As String 
    Dim strResult As String = "" 
    Dim tbox As RadNumericTextBox = Nothing 
    tbox = DirectCast(Page.Master.FindControl("tbx1"), RadNumericTextBox) 
    strResult = tbox.Text 
    Return strResult 
End Function 

-Shinu.
Tags
Input
Asked by
Michael Kovac
Top achievements
Rank 1
Answers by
Shinu
Top achievements
Rank 2
Share this question
or