Findcontrol RadnumericTextbox returns NULL

2 posts, 0 answers
  1. Michael Kovac
    Michael Kovac avatar
    4 posts
    Member since:
    Dec 2006

    Posted 03 Jun 2009 Link to this post

    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" />










    Code behind:
    Function CollectAnswer() as string


    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.

  2. Shinu
    Shinu avatar
    17764 posts
    Member since:
    Mar 2007

    Posted 04 Jun 2009 Link to this post

    Hi Michael,

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

    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 

Back to Top