Wrox Programmer Forums
| Search | Today's Posts | Mark Forums Read
BOOK: Beginning ASP.NET 4.5 : in C# and VB
This is the forum to discuss the Wrox book Beginning ASP.NET 4.5: in C# and VB by Imar Spaanjaars; ISBN: 978-1-118-31180-6
Welcome to the p2p.wrox.com Forums.

You are currently viewing the BOOK: Beginning ASP.NET 4.5 : in C# and VB 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 January 27th, 2014, 01:15 PM
Authorized User
Points: 416, Level: 7
Points: 416, Level: 7 Points: 416, Level: 7 Points: 416, Level: 7
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Nov 2013
Posts: 84
Thanks: 29
Thanked 2 Times in 2 Posts
Default Ch 8/9 accessing User Control controls

Hi Imar,

I was trying to experiment a little with the Contact Us page and create a Page_Load method that pre-fills the email form. I can't figure out how to access the user control controls from Contact.aspx.vb.

In the calculator demo we just accessed a label with 'ResultLabel.Text = ...'. But the controls for the email User Control aren't part of the Contact.aspx page directly and don't show up in Intellisense.

I started with ContactForm1., but I'm not able to tell from the Intellisense list what the next term would be.

Thanks.

Best Regards,
Alan
 
Old January 27th, 2014, 02:52 PM
Imar's Avatar
Wrox Author
Points: 70,322, Level: 100
Points: 70,322, Level: 100 Points: 70,322, Level: 100 Points: 70,322, Level: 100
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2003
Location: Utrecht, Netherlands.
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
Default

Hi there,

The Contact Form encapsulates these controls so you can't access them directly. There are a few ways around this:

1. Set the values in the Control's Load method.

2. Create properties, like the NavigateUrl in the Banner. As the backing variable they should use the associated controls. E.g. something like this:

Code:
public string FirstName 
{
  get
  {
    return FirstName.Text;
  }
  set
  {
    FirstName.Text = value;
  }
}
Then in the page that uses the contact form, you can do:

ContactForm1.FirstName = "Some default value"; // Use Profile.FirstName perhaps?

In both case, make sure you don't do this on a PostBack (check for Page.IsPostBack) or you'll wipe out the values the user entered.

Hope this helps,

Imar
__________________
Imar Spaanjaars
http://Imar.Spaanjaars.Com
Follow me on Twitter

Author of Beginning ASP.NET 4.5 : in C# and VB, Beginning ASP.NET Web Pages with WebMatrix
and Beginning ASP.NET 4 : in C# and VB.
Did this post help you? Click the button below this post to show your appreciation!
The Following User Says Thank You to Imar For This Useful Post:
AlanWheeler (January 27th, 2014)
 
Old January 27th, 2014, 05:06 PM
Authorized User
Points: 416, Level: 7
Points: 416, Level: 7 Points: 416, Level: 7 Points: 416, Level: 7
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Nov 2013
Posts: 84
Thanks: 29
Thanked 2 Times in 2 Posts
Default Ch 8/9 accessing User Control controls

Hi Imar,

Thanks for the quick reminder about creating properties. I will have to do that later as it quickly became apparent trying to do this from the contact.aspx form was going to be pretty involved.

I ended up adding 2 methods for debugging purposes in the ContactForm.ascx.vb file; a Page_Load method that loads up the form if it's not a postback (thank you very much for the reminder), and clear method behind a button.

So, when the page first loads it has a debug email ready to go, and if I want to test the client side error checking I can clear it and we're back to normal.

I'll re-approach accessing the User Control controls after I finish the book because it takes so much time to really absorb each chapter and I don't want to slow down right now.

Later...

Best Regards,
Alan
 
Old January 28th, 2014, 12:49 AM
EricCulbertson
Guest
 
Posts: n/a
Default

Quote:
Create properties, like the NavigateUrl in the Banner
i was missing this why not getting the outcome right .. appreciate the suggestions coming to help me
Received Warning




Similar Threads
Thread Thread Starter Forum Replies Last Post
Accessing controls in host page from User Control Axe BOOK: Professional Web Parts and Custom Controls ASP.NET ISBN: 0-7645-7860-X 1 March 16th, 2011 06:22 AM
Ch 9-but will learn more abt User Controls (ch 8) btcomp BOOK: Beginning ASP.NET 4 : in C# and VB 1 August 24th, 2010 11:40 AM
Accessing the Controls of a User Control? Aaron Edwards ASP.NET 2.0 Basics 6 June 16th, 2006 07:22 PM
Accessing Properties in User Controls andyj00 ASP.NET 1.0 and 1.1 Professional 16 August 1st, 2005 07:55 AM
Accessing Properties in User Controls andyj00 Classic ASP Professional 1 May 21st, 2005 02:52 PM





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