crosspage posting (smallish) problem

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
 
B

bruce barker

the correct way to do this is to define an interface (in appcode) which
define the public properties you want to expose. then have the page
implement the interface. then in postback page you can cast the previous
page to the interface and access methods/properties.

-- bruce (sqlwork.com)
 
G

Guest

thx Bruce
I've done that!


public interface ISearch
{
string SearchString
{
get { }
}

}



and I made the page behind code implement page & ISearch like so
public partial class ButtonSearchTyped2 : System.Web.UI.Page , ISearch
{



public string SearchString
{
get { return txtSearch.Text; }
}


}


now the error I get is at the interface
and it's

Compiler Error Message: CS0531: 'ISearch.SearchString.get': interface
members cannot have a definition


what gives?
I haven't put a definition in there it's an empty stub..

any ideas
regards and thanks for your time
CharlesA
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,994
Messages
2,570,223
Members
46,812
Latest member
GracielaWa

Latest Threads

Top