G
Guest
I'm using Win XP pro Visual Studio 2005 with ASP.net 2.0 and C#
in Stephen Walther's ASP.net 2.0 unleashed he gets you to do a Submit button
example with it's postBackUrl set to a different page
the idea being that by using
PreviousPage.FindControl you can get at the previous page's txtSearch
button's text
this works great
he goes on to say, you can do it much more cleanly by adding a public
property to the calling page and in the called page you can access that
page's property like so
calling page [called ButtonSearchTyped.aspx]
<script runat="server">
public string SearchString
{
get {return txtSearch.Text;}
}
</script>
called page [called ButtonSearchResultsTyped.aspx]
<script runat="server">
protected void Page_Load(object sender, EventArgs e)
{
if (Page.PreviousPage != null)
{
lblSearch.Text =
string.Format("Search for: {0}", PreviousPage.SearchString);
}
}
</script>
I get the following error in the called page
Compiler Error Message: CS0117: 'System.Web.UI.Page' does not contain a
definition for 'SearchString'
which I interpreted to mean: PreviousPage does not contain the SearchString
member
I then tried my own Page variable and assigning to it PreviousPage, but it
amounts to the same thing
why does Walther think this will work and in practice it doesn't I'm
mystified, am I stuck with FindControl?
regards and many thanks for taking the time to look and/or answer
CharlesA
in Stephen Walther's ASP.net 2.0 unleashed he gets you to do a Submit button
example with it's postBackUrl set to a different page
the idea being that by using
PreviousPage.FindControl you can get at the previous page's txtSearch
button's text
this works great
he goes on to say, you can do it much more cleanly by adding a public
property to the calling page and in the called page you can access that
page's property like so
calling page [called ButtonSearchTyped.aspx]
<script runat="server">
public string SearchString
{
get {return txtSearch.Text;}
}
</script>
called page [called ButtonSearchResultsTyped.aspx]
<script runat="server">
protected void Page_Load(object sender, EventArgs e)
{
if (Page.PreviousPage != null)
{
lblSearch.Text =
string.Format("Search for: {0}", PreviousPage.SearchString);
}
}
</script>
I get the following error in the called page
Compiler Error Message: CS0117: 'System.Web.UI.Page' does not contain a
definition for 'SearchString'
which I interpreted to mean: PreviousPage does not contain the SearchString
member
I then tried my own Page variable and assigning to it PreviousPage, but it
amounts to the same thing
why does Walther think this will work and in practice it doesn't I'm
mystified, am I stuck with FindControl?
regards and many thanks for taking the time to look and/or answer
CharlesA