Referencing a form element on a PreviousPage with ASP.NET in Visual Studio .NET 2005 Whidbey and Thanks to Keith Smith
Referencing a form element on a previous page with ASP.NET Whidbey is a little more complicated than I had initially thought. Its not horrible complicated either, but there are some tricks that I was not aware of.
1. Form elements are private to the partial class that they are contained in. In retrospect, that makes sense, however, I did not know that at the time. So, to be able to reference the form element, you need to add a public property to the partial class that exposes the field. In my example, I had
public System.Web.UI.WebControls.TextBox TextSearchTextBox
{
get { return txtSearch; } //txtSearch is the from element that I am going to reference in another page.
}
2. In the codebehind/codebeside file that will reference the results, define a a variable of the appropiate type. In my case, it was
TextBox tbInput = null;
3. To fill the TextBox
if (null != PreviousPage && PreviousPage is Default_aspx) //Default_aspx is the name of the class file from the page that posted to the current one.
{
tbInput = (TextBox)((PreviousPage as Default_aspx).TextSearchTextBox);
}
This should get things going for you.
Many thanks to Keith Smith at Microsoft for his assistance on this and for not laughing at my questions too much.