View Single Post
  #2 (permalink)  
Old January 27th, 2014, 02:52 PM
Imar's Avatar
Imar Imar is offline
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)