Problem using dynamically created textboxes

Discussion in 'ASP .Net Web Controls' started by Nathan Sokalski, Jun 17, 2005.

  1. I am making a webform that allows the user to add another textbox by
    clicking a button to allow them to enter however many names they need. The
    procedure that does this uses information entered in the currently existing
    textboxes. This works fine the first time they click the button, since the
    first textbox is hardcoded. However, the second time they click the button I
    recieve an error saying:

    [NullReferenceException: Object reference not set to an instance of an
    object.]
    PAPresenters.register.btnAddName_Click(Object sender, EventArgs e) in
    c:\inetpub\wwwroot\PAPresenters\register.aspx.vb:128
    System.Web.UI.WebControls.Button.OnClick(EventArgs e)
    System.Web.UI.WebControls.Button.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String
    eventArgument)
    System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler
    sourceControl, String eventArgument)
    System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData)
    System.Web.UI.Page.ProcessRequestMain()

    When I do a view source on the page, it gave the generated textboxes the ID
    that I told it to. I think the problem has something to do with ASP.NET
    forgetting the new controls when it looks for them the second time or
    something. The line of code where I recieve the error is:

    Line 126: 'Make sure there are no empty name fields
    Line 127: For i As Integer = 0 To namecount
    Line 128: If CType(FindControl("txtFName" & CStr(i)),
    TextBox).Text = "" OrElse CType(FindControl("txtLName" & CStr(i)),
    TextBox).Text = "" Then
    Line 129: Exit Sub
    Line 130: End If

    Why is ASP.NET unable to find the dynamically created controls? Thanks.
    --
    Nathan Sokalski

    http://www.nathansokalski.com/
     
    Nathan Sokalski, Jun 17, 2005
    #1
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Forconi Boris via .NET 247

    TextBoxes created dynamically : How to store data?

    Forconi Boris via .NET 247, Jun 17, 2004, in forum: ASP .Net
    Replies:
    2
    Views:
    393
    Trevor Benedict R
    Jun 18, 2004
  2. SD
    Replies:
    3
    Views:
    477
    =?Utf-8?B?S2V6emE=?=
    Jun 23, 2005
  3. RC
    Replies:
    1
    Views:
    609
    Teemu Keiski
    Jun 7, 2005
  4. Nathan Sokalski

    Problem using dynamically created textboxes

    Nathan Sokalski, Jun 17, 2005, in forum: ASP .Net
    Replies:
    0
    Views:
    407
    Nathan Sokalski
    Jun 17, 2005
  5. msimmons
    Replies:
    0
    Views:
    551
    msimmons
    Jul 16, 2009
Loading...

Share This Page