473,394 Members | 1,811 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,394 software developers and data experts.

Master page postback.. !IsPostback doesnt work

Hi there,

I dont this this a bug but i cant get my head around it.. I have a
master page that has a login control on it, to log in i press the
button and the page posts back, however on the page that is derived
from the master page (default.aspx) i have code that i dont want to
run after the login button is pressed so i used the standard

if(!Page.IsPostBack) {}

to try and hide the code on default.aspx, however since the postbsck
comes from the control in the master page this code still runs???

How do i stop this code running in default.aspx whn the login button
in the aster page is clicked??

Cheers
Anthony

Jul 9 '07 #1
6 15835
<an***********@googlemail.comwrote in message
news:11**********************@o61g2000hsh.googlegr oups.com...
Hi there,

I dont this this a bug but i cant get my head around it.. I have a
master page that has a login control on it, to log in i press the
button and the page posts back, however on the page that is derived
from the master page (default.aspx) i have code that i dont want to
run after the login button is pressed so i used the standard

if(!Page.IsPostBack) {}

to try and hide the code on default.aspx, however since the postbsck
comes from the control in the master page this code still runs???

How do i stop this code running in default.aspx whn the login button
in the aster page is clicked??
A couple of things...

Firstly, in the MasterPage / ContentPage scenario, content pages aren't
"derived" from master pages - quite the reverse! In fact, a MasterPage is
really nothing more than a UserControl.

Secondly, master pages are intended to provide common look and feel (and
sometimes functionality) across several pages, possibly an entire site. If
you have functionality in your master page which is intended for only one
content page, then that functionality would be better placed in the content
page itself, not the master page...
--
Mark Rae
ASP.NET MVP
http://www.markrae.net

Jul 9 '07 #2
Hi Mark,

Thanks for your reply but i dont think you quite understood what my
problem was..

The user control in the master page (login.ascx) does need to be on
every page, the only problem i have is that when i click this login
button and the page posts back all the code in default.aspx page_load
posts again even if i use the !IsPostback statement?? Why is this flag
not stopping the page_load code from executing in the default.aspx
page??

Anthony

Jul 9 '07 #3
A "Postback" is a re-request (via HTTP POST) of the page, which means that
everything - page and MasterPage get reloaded. So if this behavior is giving
you issues, you need to re-think your logic to accomodate.
-- Peter
Site: http://www.eggheadcafe.com
UnBlog: http://petesbloggerama.blogspot.com
BlogMetaFinder(BETA): http://www.blogmetafinder.com

"an***********@googlemail.com" wrote:
Hi Mark,

Thanks for your reply but i dont think you quite understood what my
problem was..

The user control in the master page (login.ascx) does need to be on
every page, the only problem i have is that when i click this login
button and the page posts back all the code in default.aspx page_load
posts again even if i use the !IsPostback statement?? Why is this flag
not stopping the page_load code from executing in the default.aspx
page??

Anthony

Jul 9 '07 #4
You could also write the value to make sure your assumption is correct. For
now I would write down the value to make sure it's incorrect. Actually for
now I would expect that the value is correct but that you do something that
doesn't need the code to run (for example when you postback, control values
are populated from posted values even if you don't bind data etc...)

---
Patrice
"Peter Bromberg [C# MVP]" <pb*******@yahoo.yabbadabbadoo.coma écrit dans
le message de news: 72**********************************@microsoft.com...
>A "Postback" is a re-request (via HTTP POST) of the page, which means that
everything - page and MasterPage get reloaded. So if this behavior is
giving
you issues, you need to re-think your logic to accomodate.
-- Peter
Site: http://www.eggheadcafe.com
UnBlog: http://petesbloggerama.blogspot.com
BlogMetaFinder(BETA): http://www.blogmetafinder.com

"an***********@googlemail.com" wrote:
>Hi Mark,

Thanks for your reply but i dont think you quite understood what my
problem was..

The user control in the master page (login.ascx) does need to be on
every page, the only problem i have is that when i click this login
button and the page posts back all the code in default.aspx page_load
posts again even if i use the !IsPostback statement?? Why is this flag
not stopping the page_load code from executing in the default.aspx
page??

Anthony


Jul 9 '07 #5
Hi all,

Thanks for your replies but i still think im not being clear.. on
default.aspx i have the following code

if (!Page.IsPostBack)
{
string page;

if (Request.QueryString["PageID"] != null)
page = Request.QueryString["PageID"].ToString();
}

Obviously this code runs the first time the page loads, then when
someone logs in they press the submit button in the login control on
the masterpage causing the page to "postback". However when this
"postback occurs the above code runs when i thought the if (!
Page.IsPostBack) would stop the code running as i have just posted the
page from the login ox.. Why does this code run??

Cheers
Anthony

Jul 9 '07 #6
Well have you tried to display Page.IsPostBack as asked previously ? How do
you know for sure that this code runs. Sorry for being picky but sometimes
we start from the assumption that a portion of code runs when actually it is
some other portion that does the job or because the code doesn't need to run
to get the same effect....

I would like to make 100% sure that IsPostBack doesn't return the correct
value. The best way is to just print this value to see wether or not it is
false. You could also dump Request.ServerVariables("HTTP_METHOD") to see if
it"'s GET or POST.

For example if you have some other code that does a redirect once the
postback for login occurs (which is perhaps the case with the standard
RedirectFromLogin method) then you would have a postback that does a
redirect and finally you are not seeing a postback in your code (i.e. you'll
see postback being false and the method being GET)...

--
Patrice
<an***********@googlemail.coma écrit dans le message de news:
11**********************@n60g2000hse.googlegroups. com...
Hi all,

Thanks for your replies but i still think im not being clear.. on
default.aspx i have the following code

if (!Page.IsPostBack)
{
string page;

if (Request.QueryString["PageID"] != null)
page = Request.QueryString["PageID"].ToString();
}

Obviously this code runs the first time the page loads, then when
someone logs in they press the submit button in the login control on
the masterpage causing the page to "postback". However when this
"postback occurs the above code runs when i thought the if (!
Page.IsPostBack) would stop the code running as i have just posted the
page from the login ox.. Why does this code run??

Cheers
Anthony

Jul 9 '07 #7

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

Similar topics

7
by: Martijn Saly | last post by:
Hi there, I've created a master page with some controls on it, a Calendar control among others. Now depending on the date(s) selected, the content page needs to be updated. In the masterpage...
5
by: Vincent A. | last post by:
Hello, I'm developping an asp.net application which used master page on which i add several web control. One of the them is a menu control which as several button in order to develop each sub...
9
by: ad | last post by:
Hi, How can I dynamically change the MasterPager of a web page?
5
by: John | last post by:
I have textbox control on a masterpage. Now when we type something in textbox and press the enter key, i want it to post to another page.aspx. How can i do this? Thanks.
4
by: Diane Yocom | last post by:
I'm trying to use an Atlas UpdatePanel to just update a label when a text box has changed. The problem is that my textbox is in a user control and I'm using Master Pages - with the combination of...
0
by: dhurwitz | last post by:
Hi, In my ASP.NET 2.0 web app, I have a user control, ucBinEdges, with several text boxes. The user control has several validation controls validating the Text of these text boxes -...
2
by: igotyourdotnet | last post by:
Is there a way to prevent the master page to reload every time the user makes a selection off of the menu? I want to give it a "Frame" like appearance were only the content section changes with a...
0
by: =?Utf-8?B?TWFyayBHaWxrZXM=?= | last post by:
I have designed and written a custom menu like server control. The control inherits from DataBoundControl and implements INamingContainer and IPostBackEventHandler interfaces. The control uses only...
4
by: scottingim | last post by:
I have set up a updateprogress on my master page. It contains a label, so I can give page-appropriate messages while updates are going on. However, I cannot update the label. Here is the...
4
by: Seth Williams | last post by:
If I have some Master Page properties, and assign them when the master page first loads, knowing that I can access these property values in the current Content pages, will these properties be...
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?
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,...

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.