473,396 Members | 1,879 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

crosspage posting (smallish) problem

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

Feb 15 '07 #1
3 1338
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)

CharlesA wrote:
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
Feb 15 '07 #2
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
Feb 15 '07 #3
He has probably added @PreviousPageType directive on the target page, which
strongly-types the PreviousPage property based on the code-behind class of
the source page.
http://msdn2.microsoft.com/en-us/lib...69(VS.80).aspx

--
Teemu Keiski
AspInsider, ASP.NET MVP
http://blogs.aspadvice.com/joteke
http://teemukeiski.net
"CharlesA" <Ch******@discussions.microsoft.comwrote in message
news:C3**********************************@microsof t.com...
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
Feb 16 '07 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Roger Walter | last post by:
I have a .Net web page that is posting twice after the submit button is clicked once. How can that happen? I have turned tracing on and it writes two records to the trace log and posts twice. ...
2
by: Rabbit | last post by:
Dear All, I've been tried various configuration and did install SP1 on Windows 2003 Server. The problem now that I have is an aspx page located on the web site for taking the file post by...
29
by: Gernot Frisch | last post by:
Hi, I have no clue. - I want to align the red, green, blue boxes in one line - red,green,blue must be 45px high - red (center) must be as wide as possible - yellow must start exactly below...
2
by: FAQ server | last post by:
----------------------------------------------------------------------- FAQ - What do I have to do before posting to clj? ----------------------------------------------------------------------- ...
0
by: tofu.captain | last post by:
I have an ASPX page that needs to read in form values (txtbox, dropdownlists, etc) from a custom control that redirects execution by crosspage postback. Here is the how it is being redirected: ...
2
by: FAQ server | last post by:
----------------------------------------------------------------------- FAQ Topic - What do I have to do before posting to clj?...
1
PEB
by: PEB | last post by:
POSTING GUIDELINES Please follow these guidelines when posting questions Post your question in a relevant forum Do NOT PM questions to individual experts - This is not fair on them and...
0
iam_clint
by: iam_clint | last post by:
Javascript vs JSP I would like to note that JSP and JS are 2 different languages and are not used for the same thing. You would find better help for jsp posting under the Java forum. Posting...
1
by: =?Utf-8?B?WWFua2VlIEltcGVyaWFsaXN0IERvZw==?= | last post by:
is there a way to cancel a cross-page post back on a condition. i'm processing a credit card and on success i'm posting to the receipt page. Any way to cancel on a failure? (or any other...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.