Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > ASP.NET and ASP > ASP.NET 4.5 > BOOK: Beginning ASP.NET 4.5 : in C# and VB
Password Reminder
Register
| FAQ | Members List | Calendar | 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 tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
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
Reply With Quote
  #2 (permalink)  
Old January 27th, 2014, 02:52 PM
Imar's Avatar
Wrox Author
Points: 72,055, Level: 100
Points: 72,055, Level: 100 Points: 72,055, Level: 100 Points: 72,055, Level: 100
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2003
Location: Utrecht, Netherlands.
Posts: 17,086
Thanks: 80
Thanked 1,587 Times in 1,563 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!
Reply With Quote
The Following User Says Thank You to Imar For This Useful Post:
AlanWheeler (January 27th, 2014)
  #3 (permalink)  
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
Reply With Quote
  #4 (permalink)  
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
Reply With Quote Received Warning
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


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



All times are GMT -4. The time now is 01:46 AM.


Powered by vBulletin®
Copyright ©2000 - 2019, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.