Wrox Programmer Forums
| Search | Today's Posts | Mark Forums Read
ASP.NET 1.0 and 1.1 Basics ASP.NET discussion for users new to coding in ASP.NET 1.0 or 1.1. NOT for the older "classic" ASP 3 or the newer ASP.NET 2.0.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the ASP.NET 1.0 and 1.1 Basics section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
  #1 (permalink)  
Old June 10th, 2004, 07:10 AM
Registered User
 
Join Date: Jun 2004
Location: Manchester, , .
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to coddy
Default Usercontrols problem

OK not sure if this is the right subject for this. but i hope someone can help or point me in the right direction.

What i have is various usercontrols with textboxes etc on.
What i am trying to do is capture the values of the textboxes within the usercontrol, in the usercontrol itself.

However the submit button is actually on the parent page.
The reason for this is I would like to add as many or as few usercontrols onto the page dependant on specific criterea.

However when the page is submitted and the function to grab tha values is fired, i keep getting an "Object reference is not set to an instance ... " error.

I know i can just add the button to the usercontrol itself, but if i load to user controls onto one page i will have 2 submit buttons.

Can someone please help me as going mad. I hope i explained myself well enough if not please reply.

Thanks in advance
Nigel

(moved to correct forum -planoie)
  #2 (permalink)  
Old June 10th, 2004, 08:13 AM
planoie's Avatar
Friend of Wrox
Points: 16,481, Level: 55
Points: 16,481, Level: 55 Points: 16,481, Level: 55 Points: 16,481, Level: 55
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Aug 2003
Location: Clifton Park, New York, USA.
Posts: 5,407
Thanks: 0
Thanked 16 Times in 16 Posts
Default

How are you adding the user controls to the page?
What is the object that is reported as not being instanced?
  #3 (permalink)  
Old June 10th, 2004, 08:24 AM
Authorized User
 
Join Date: May 2004
Location: , , USA.
Posts: 24
Thanks: 0
Thanked 0 Times in 0 Posts
Default

If you are accessing the text box on the server (within your user control), there should not be a problem, if the control is defined in your code behind file. However, on the client side, you should access it as document.all("<use control name>:<textboxname>").


SS
  #4 (permalink)  
Old June 10th, 2004, 08:25 AM
Registered User
 
Join Date: Jun 2004
Location: Manchester, , .
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to coddy
Default

OK I am adding the usercontrols to the page by

Control myControl = Page.LoadControl("form1.ascx");
QuestionsPlace.Controls.Add(myControl);

QuestionsPlace being the placeholder.

on form1.ascx I have various textboxes and dropdownlists .. and its the first textbox on the page that causes the error.
  #5 (permalink)  
Old June 10th, 2004, 08:34 AM
Registered User
 
Join Date: Jun 2004
Location: Manchester, , .
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to coddy
Default

Hi sundar

I dont think i have explained myself properly ..

The button is on the parent page. And by the time my function within the usercontrol is called. I get the error
"Object reference is not set to an instance ... myTxtBox.Text or whatever is the first thing to check"

I do have no problems accessing the textbox if i include a button onto the usercontrol itself, but i would like to try and get it working this way so i can add as many usercontrols on to the page and still only have one submit button
  #6 (permalink)  
Old June 11th, 2004, 11:23 AM
planoie's Avatar
Friend of Wrox
Points: 16,481, Level: 55
Points: 16,481, Level: 55 Points: 16,481, Level: 55 Points: 16,481, Level: 55
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Aug 2003
Location: Clifton Park, New York, USA.
Posts: 5,407
Thanks: 0
Thanked 16 Times in 16 Posts
Default

Can you post the code that you are using to get the values from the textbox?

As I understand it, you want to retrieve the textbox values (textboxes in the user control(s)) in the handler for the button click event (button is on the page). Normally, to do this, you need to create a public property on the user control that exposes the .Text property of textbox within the user control. You can't reference the textbox by name because the page has no knowledge of the textbox, only the user control. Post again if you still need help with this.


Similar Threads
Thread Thread Starter Forum Replies Last Post
Problem with Precompiled Usercontrols ramki16 ASP.NET 2.0 Professional 0 April 9th, 2008 04:21 AM
Usercontrols yveerabhadrarao ADO.NET 1 August 3rd, 2007 06:57 AM
Linking UserControls dhanyavnair Pro VB 6 2 December 1st, 2004 02:41 PM
Postback for usercontrols anuradha80 General .NET 4 September 27th, 2004 11:35 PM
Reusability of UserControls jara VS.NET 2002/2003 0 August 14th, 2003 05:52 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.