Jump to content

Cross Page Postback from a Master Page

Whether you're a seasoned veteran or a struggling beginner, Web Radiance is the web development and web design forum for you. You'll find answers to all your HTML, CSS, SEO, and Programming needs. Pull up a chair and stay awhile.

Page 1 of 1
  • You cannot start a new topic
  • This topic is locked

Cross Page Postback from a Master Page Rate Topic: -----

#1 User is offline   Catalyst 

  • Codesmith
  • Group: Administrators
  • Posts: 1,049
  • Joined: 04-April 06
  • Gender:Male
  • Location:San Diego

Posted 01 October 2006 - 03:28 AM

The new cross page postbacks are handy but my first attempt to use them resulted in null objects when I'd try to use PreviousPage.FindControl()

After no luck finding anything on the web I messed around a bit and found that if your original page uses Master pages then you have to work your way through a longer control hierarchy.

PreviousPage.Master.FindControl("contentplaceholder1").FindControl("whatiwant")

0

#2 User is offline   marcamos 

  • W.R. General
  • Group: Administrators
  • Posts: 2,849
  • Joined: 04-April 06
  • Gender:Male
  • Location:Massachusetts - USA

Posted 01 October 2006 - 06:14 PM

Not to entirely dumb down this topic, but to those of us unfamiliar with ASP, what (in lamens terms) does this feature do or mean?
0

#3 User is offline   Catalyst 

  • Codesmith
  • Group: Administrators
  • Posts: 1,049
  • Joined: 04-April 06
  • Gender:Male
  • Location:San Diego

Posted 01 October 2006 - 07:23 PM

Short answer: It won't make much sense unless you do asp.net 2.0

Long answer:
Normally an asp.net page reloads itself when you interact with it in different ways, such as clicking a button. The button click even is then fired on the server and your code handles that event however you'd like.

So by default asp.net pages post their form data back to themselves and they maintain the status of all the controls on the page through these reloads.

For example in PHP, etc you might make an email form that send the data back to itself to check that everything is valid rather than posting the form straight to another page. You'd have to write some code for the page to reload all the form fields from the POST data if they needed to be corrected by the user. ASP.NET takes care of that automatically.

The more unusual thing to do in ASP.NET is to post the page's data to a different page, which is what the cross page postback allows you to do. You can then access information about all of the controls on the previous page.

Master pages is in a sense a way of templating a website without using include files.

The problem I ran into was that doing a cross page postback from a page that used a Master Page template, the controls were at a deeper level than normal so all the code samples out there didn't work.
0

#4 User is offline   marcamos 

  • W.R. General
  • Group: Administrators
  • Posts: 2,849
  • Joined: 04-April 06
  • Gender:Male
  • Location:Massachusetts - USA

Posted 01 October 2006 - 08:39 PM

I'm shocked to say that I actually understand all that. In a slightly off-topic question, it appears you prefer asp.net over PHP. Is this true, or just the dev environment in this situation?
0

#5 User is offline   Catalyst 

  • Codesmith
  • Group: Administrators
  • Posts: 1,049
  • Joined: 04-April 06
  • Gender:Male
  • Location:San Diego

Posted 01 October 2006 - 11:27 PM

I always felt that classic ASP and PHP were about equal. PHP had some funny syntax I've never been crazy about but that's pretty minor.

When ASP.NET 1.0 came out I took a good look at it, read a book on it, and ultimately didn't really like it. When 2.0 came out I took another look and they'd changed so much about it and MS is going in such a better direction that it's a shame they're even called the same thing. I really like asp.net 2 and since my first site with it I haven't gone back.

It's not ASP.NET 2.0 specifically that I prefer over PHP/classic ASP. I think J2EE, ASP.NET, or Ruby on Rails are all comparable and all better.
0

#6 User is offline   Karl Buckland 

  • A.K.A. Sirkent
  • Group: Administrators
  • Posts: 2,145
  • Joined: 04-April 06
  • Gender:Male
  • Location:Kent, UK

Posted 02 October 2006 - 05:40 AM

View PostCatalyst, on Oct 2 2006, 01:23 AM, said:

For example in PHP, etc you might make an email form that send the data back to itself to check that everything is valid rather than posting the form straight to another page. You'd have to write some code for the page to reload all the form fields from the POST data if they needed to be corrected by the user. ASP.NET takes care of that automatically.


But that realistically doesn't take more than 5 minutes does it? And you'll probably want to do some verification of that data anyway, so you'll be accessing those variables regardless?

I'm not going to get into a big PHP vs anything else debtate, but at the end of the day there are reasons for and against pretty much all of the different technologies available today. .NET, J2EE and Ruby on Rails all follow the MVC architecture (correct me if I'm wrong) and so in the long run that can make them easier to develop for, more scalable and more at an enterprise level. But I still prefer PHP :P.
QUOTE(benbramz @ Aug 17 2007, 07:44 AM) Ive noticed that quite a few people are now adding quotes from the board into their signature. I think its started an new web-radiance craze.. :P
0

#7 User is offline   Catalyst 

  • Codesmith
  • Group: Administrators
  • Posts: 1,049
  • Joined: 04-April 06
  • Gender:Male
  • Location:San Diego

Posted 02 October 2006 - 01:46 PM

View PostSirkent, on Oct 2 2006, 11:40 AM, said:

But that realistically doesn't take more than 5 minutes does it?


True, it was just a simple example.

View PostSirkent, on Oct 2 2006, 11:40 AM, said:

.NET, J2EE and Ruby on Rails all follow the MVC architecture (correct me if I'm wrong) and so in the long run that can make them easier to develop for, more scalable and more at an enterprise level. But I still prefer PHP :P.


The MVC model and stronger OOP really doesn't bear fruit until you're working on a certain complexity of site, and everyone's got their language preference of course - as you say they all have their good and bad. My personal interest just happens to be in the architected web application direction.
0

Share this topic:


Page 1 of 1
  • You cannot start a new topic
  • This topic is locked

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users