Wrox Programmer Forums
Go Back   Wrox Programmer Forums > ASP.NET and ASP > ASP.NET 2.0 > ASP.NET 2.0 Basics
|
ASP.NET 2.0 Basics If you are new to ASP or ASP.NET programming with version 2.0, this is the forum to begin asking questions. Please also see the Visual Web Developer 2005 forum.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the ASP.NET 2.0 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
 
Old April 4th, 2007, 07:31 AM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 2,189
Thanks: 5
Thanked 59 Times in 57 Posts
Send a message via MSN to gbianchi
Default

hi there..

well.. i see your problem... your txtemail control is inside an user control!!!!

so you first have to look for the user control inside the placeholder, then you have to look for the txtemail box inside that control..

that's why you never find it...

and also you are never giving your user control an ID... please add one to it so you can find it...



HTH

Gonzalo

================================================== =========
Read this if you want to know how to get a correct reply for your question:
http://www.catb.org/~esr/faqs/smart-questions.html
^^Took that from dparsons signature and he Took that from planoie's profile
================================================== =========
My programs achieved a new certification (can you say the same?):
WORKS ON MY MACHINE
http://www.codinghorror.com/blog/archives/000818.html
================================================== =========
 
Old April 4th, 2007, 08:09 AM
Authorized User
 
Join Date: Dec 2006
Posts: 35
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Gonzalo,

How do I assign my user control an id? It's an ascx file (UserControl.ascx) which just contains <asp:> controls. It inherits the UserControl class from the codebehind (UserControl.ascx.vb).

Peter,

I am already doing that to set other properties on the class.

In fact I have multiple controls in UserControl which relate to a User i.e. Name, Email, etc.

I set them to be visible or not depending on whether I want to display them or not.

So as I already have the UserControl class (cUserControl) I can easily add this property, but I'm loading the control and adding it to the placeholder in the Page_Init event now.

I need to access that value when I get to the Page_Load event?

Do you think I can safely move the page_init code back to the page_load event?

This would really tie things up!

Thanks,

Paul






http://www.thewebsiteshop.co.uk
 
Old April 4th, 2007, 08:17 AM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 2,189
Thanks: 5
Thanked 59 Times in 57 Posts
Send a message via MSN to gbianchi
Default

using your code, simple as:
Code:
myUserControl.id = "thenameyouwant"
if you keep that line (and the one that's load the control) on the form_load and outside the postback you will find the control every time you need it...

HTH

Gonzalo

================================================== =========
Read this if you want to know how to get a correct reply for your question:
http://www.catb.org/~esr/faqs/smart-questions.html
^^Took that from dparsons signature and he Took that from planoie's profile
================================================== =========
My programs achieved a new certification (can you say the same?):
WORKS ON MY MACHINE
http://www.codinghorror.com/blog/archives/000818.html
================================================== =========
 
Old April 4th, 2007, 08:21 AM
planoie's Avatar
Friend of Wrox
 
Join Date: Aug 2003
Posts: 5,407
Thanks: 0
Thanked 16 Times in 16 Posts
Default

Paul,

One answer, like Gonzalo said, is to keep the control outside of a specific method. Declare the control variable in the page class scope, instantiate it wherever you need, and you can access the control anywhere on the page. It will behave just like a control created declaratively in the page's markup.

-Peter
 
Old April 4th, 2007, 08:56 AM
Authorized User
 
Join Date: Dec 2006
Posts: 35
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Wowee,

Works like a charm! That's so cool.

When you're fairly new to things you tend to overcomplicate matters - the solution here is elegantly straightforward.

Thanks guys, your advice was top dollar.

All the very best,

Paul



http://www.thewebsiteshop.co.uk





Similar Threads
Thread Thread Starter Forum Replies Last Post
Problem w/ dynamically added controls in GridView jpamental Pro Visual Basic 2005 2 May 12th, 2006 09:10 AM
Dynamically added panel with radio buttons ADM10 Visual Basic 2005 Basics 1 May 11th, 2006 10:27 PM
Capturing Dynamically Added Client Values Colonel Angus ASP.NET 1.0 and 1.1 Professional 4 April 14th, 2006 12:38 PM
Raise Event for Dynamically Added DropDownList DolphinBay ASP.NET 1.0 and 1.1 Professional 3 December 6th, 2005 02:22 PM
Control not added to code page shmacgregor VS.NET 2002/2003 2 March 26th, 2004 05:49 PM





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