473,396 Members | 1,805 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.

How do I do cross page posting from a master page?

Hello,

I would like to add a search text box to the master page, so that it
appears on every page of the site. I then want the button next to the
search box to do a cross page post to the search page, where I want to
pick up the contents of the search box.

Trouble is, I can't see how to get at the text box on the master page.
My code follows:-

This is on the master page's .master file...

<asp:TextBox ID="txtFind" RunAt="server" />
<asp:Button ID="btnFind" PostBackUrl="Search.aspx" Text="Find"
RunAt="server" />

and the code-behind for the master contains...

public partial class MasterPage : System.Web.UI.MasterPage {
public string searchKeywords {
get {return txtFind.Text;}
}
}

The Search.aspx.cs file contains this...

public partial class Search : Page {
public void Page_Load(Object o, EventArgs e) {
if (!IsPostBack) {
if (PreviousPage != null && PreviousPage.IsCrossPagePostBack) {
MasterPage masterPage = (MasterPage)PreviousPage;
if (masterPage != null) {
// we're in business, do the search
}
}
}
}
}

However I get a compilation error "Cannot convert type
'System.Web.UI.Page' to 'System.Web.UI.MasterPage'" on the line...

MasterPage masterPage = (MasterPage)PreviousPage;

Any ideas? TIA

--
Alan Silver
(anything added below this line is nothing to do with me)
Jan 18 '06 #1
4 3605
Not sure, but I can give you a wonderful clue that might help:

The master page is implemented as a User Control. Not sure how it is wired,
but that should give you a direction to head when you look for answers.

--
Gregory A. Beamer
MVP; MCP: +I, SE, SD, DBA

***************************
Think Outside the Box!
***************************
"Alan Silver" wrote:
Hello,

I would like to add a search text box to the master page, so that it
appears on every page of the site. I then want the button next to the
search box to do a cross page post to the search page, where I want to
pick up the contents of the search box.

Trouble is, I can't see how to get at the text box on the master page.
My code follows:-

This is on the master page's .master file...

<asp:TextBox ID="txtFind" RunAt="server" />
<asp:Button ID="btnFind" PostBackUrl="Search.aspx" Text="Find"
RunAt="server" />

and the code-behind for the master contains...

public partial class MasterPage : System.Web.UI.MasterPage {
public string searchKeywords {
get {return txtFind.Text;}
}
}

The Search.aspx.cs file contains this...

public partial class Search : Page {
public void Page_Load(Object o, EventArgs e) {
if (!IsPostBack) {
if (PreviousPage != null && PreviousPage.IsCrossPagePostBack) {
MasterPage masterPage = (MasterPage)PreviousPage;
if (masterPage != null) {
// we're in business, do the search
}
}
}
}
}

However I get a compilation error "Cannot convert type
'System.Web.UI.Page' to 'System.Web.UI.MasterPage'" on the line...

MasterPage masterPage = (MasterPage)PreviousPage;

Any ideas? TIA

--
Alan Silver
(anything added below this line is nothing to do with me)

Jan 18 '06 #2
>Not sure, but I can give you a wonderful clue that might help:

The master page is implemented as a User Control. Not sure how it is wired,
but that should give you a direction to head when you look for answers.


Hmm, maybe I didn't get enough sleep last night (as usual!!), but I
don't see what you're getting at. Even if it a user control, I still
need to be able to cast it to something that the compiler will know has
the property I added for the textbox. I don't see how a user control is
any better than a master page in that respect.

Please could you be more explicit? Thanks

--
Alan Silver
(anything added below this line is nothing to do with me)
Jan 18 '06 #3
Try adding the @MasterType and @PreviousPageType to your second ASPX page.
Then use this:

(TextBox)PreviousPage.Master.FindControl("txtFind" )

Hope this helps!
--
Christopher A. Reed
"The oxen are slow, but the earth is patient."

"Alan Silver" <al*********@nospam.thanx.invalid> wrote in message
news:EI**************@nospamthankyou.spam...
Hello,

I would like to add a search text box to the master page, so that it
appears on every page of the site. I then want the button next to the
search box to do a cross page post to the search page, where I want to
pick up the contents of the search box.

Trouble is, I can't see how to get at the text box on the master page.
My code follows:-

This is on the master page's .master file...

<asp:TextBox ID="txtFind" RunAt="server" />
<asp:Button ID="btnFind" PostBackUrl="Search.aspx" Text="Find"
RunAt="server" />

and the code-behind for the master contains...

public partial class MasterPage : System.Web.UI.MasterPage {
public string searchKeywords {
get {return txtFind.Text;}
}
}

The Search.aspx.cs file contains this...

public partial class Search : Page {
public void Page_Load(Object o, EventArgs e) {
if (!IsPostBack) {
if (PreviousPage != null && PreviousPage.IsCrossPagePostBack) {
MasterPage masterPage = (MasterPage)PreviousPage;
if (masterPage != null) {
// we're in business, do the search
}
}
}
}
}

However I get a compilation error "Cannot convert type
'System.Web.UI.Page' to 'System.Web.UI.MasterPage'" on the line...

MasterPage masterPage = (MasterPage)PreviousPage;

Any ideas? TIA

--
Alan Silver
(anything added below this line is nothing to do with me)

Jan 21 '06 #4
>Try adding the @MasterType and @PreviousPageType to your second ASPX page.
Then use this:

(TextBox)PreviousPage.Master.FindControl("txtFind ")

Hope this helps!


Thanks for the suggestion, but I don't think I can do this as I won't
know the PreviousPageType. As the search box is on the master page, it
appears on every page of the site, so the PreviousPageType could be any
page on the site.

Any other ideas? Thanks again.

--
Alan Silver
(anything added below this line is nothing to do with me)
Jan 22 '06 #5

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

Similar topics

7
by: David Hayes | last post by:
I tried finding an answer on http://www.quirksmode.org/ without success. I am attempting a complicated Frames structure. I have made it work in IE, but not Netscape. I begin with three...
10
by: Atul Bahl | last post by:
I am not able to reference values by using cross page postings when using master page. Currently I am runing on beta 2 of CLR. Any ideas... Thanks Atul
5
by: Bryan | last post by:
I am trying to get to a label control to get its Text value. from a previous page. The label control is buried in a Web User Control that is in a webpart zone. When I use this code:...
1
by: Jason | last post by:
I have page1.aspx that a user enters data in some form fields. Page1.aspx's form fields are placed within a Content Place Holder on the page and the page is using a Master Page. Page1.aspx posts to...
0
by: steve.craver | last post by:
I am working with a multi-field search form which, when the form is submitted, queries a database and returns the results into a paginated GridView object. The site is being developed with master...
2
by: Vu Truong | last post by:
Hello, I try to use PostBackUrl to cross post between 2 pages on difference application. At the first time, I press the button on source page. Check on target page, I see Request.Form is...
2
by: deshg | last post by:
Hey everyone, I am a php programmer originally and am just helping a friend of mine update their website that they paid a designer (well that's what he called himself!) to do ages ago. I have...
6
by: =?Utf-8?B?SmF5IFBvbmR5?= | last post by:
I am trying to access a Public property on a Master Page from a Base Page. On the content pages I have the MasterType Directive set up as follows: <%@ MasterType virtualpath="~/Master.master" %>...
8
by: =?Utf-8?B?V2ViQnVpbGRlcjQ1MQ==?= | last post by:
I the page knows there was a cross post back. but i can not find the control. (asp.net 3.5) calling page has a master calling control: <asp:Button ID="btnSendAlert" runat="server" Text="Go"...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
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: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
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
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

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.