Master page postback.. !IsPostback doesnt work

ASP.NET

    Sponsored Links

    Next

  • 1. Help with report printing using reportviewer
    Hi, I have an ASP net application that generates some reports. I'm using the reporting tool that came whith vs2005 and the report viewer to show them. The report is processed in local mode. Anyone knows how to print a report using the report viewer in localmode? Is it possible to define the page orientation when exporting to PDF (it exports in a portrait and i need to export in landscape)? Thanks a lot.
  • 2. LoginView - Roles and Common Stuff
    Hello All, Is there a way to show common "stuff" in the LoginView for all logged in users when using <RoleGroups>? In other words, I have a number of links that all users that log in should see. There are additional links special to particular roles. It appears that I need to do something like (plus usual parameters like runat="server"): <asp:LoginView> <AnonymousTemplate>You are not logged in</AnonymousTemplate> <RoleGroups> <asp:RoleGroup Roles="RegularUser"> <ContentTemplate> <asp:HyperLink NavigateUrl="~/Common1.aspx">Common Link #1</asp:HyperLink> <asp:HyperLink NavigateUrl="~/Common2.aspx">Common Link #2</asp:HyperLink> </ContentTemplate> </asp:RoleGroup> </RoleGroups> <ContentTemplate> <asp:RoleGroup Roles="Administrator"> <asp:HyperLink NavigateUrl="~/Common1.aspx">Common Link #1</asp:HyperLink> <asp:HyperLink NavigateUrl="~/Common2.aspx">Common Link #2</asp:HyperLink> <asp:HyperLink NavigateUrl="~/AdminOnly.aspx">Admin Only Link</asp:HyperLink> </asp:RoleGroup> </ContentTemplate> </RoleGroups> </asp:LoginView> It seems silly (and error-prone) to have to put the "Common Link #1" and "Common Link #2" into both RoleGroups. Isn't there a better way? Thanks, pagates
  • 3. menu controls on 2.0 ..
    As I surf the net I see so many cool drop down menus.. I'm wondering are most of those non .net or third party? Perhaps I just don't know what I'm doing in vs.net, but the delivered menus do seem kinda lame. I've read there is no way to remove that little arrow when there are sub menu items? True? Also, how do build a horizontal menu where individual items have a border around them and transparent or blank spaces between them? do I have to insert my own image to do this? I hope not.
  • 4. How to Access HTML Controls from code behind ?
    Hi , I have a table which needs to be populated at runtime. Is there a way to do this without using a server side control like repeater or datagrid ? How can an HTML control be accessed in code behind ? Thanks in advance ..
  • 5. Computer name could not be obtai
    I received the error "Computer name could not be obtain" when i run a winservice that uses a proxy to run some application. Sorry my english..! Exception Details: System.InvalidOperationException: Computer name could not be obtained. Somebody knows how to solve it?? Regards...!

Master page postback.. !IsPostback doesnt work

Postby anthonykallay » Tue, 10 Jul 2007 18:54:19 GMT

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


Re: Master page postback.. !IsPostback doesnt work

Postby Mark Rae [MVP] » Tue, 10 Jul 2007 19:05:45 GMT






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.**--****.com/  


Re: Master page postback.. !IsPostback doesnt work

Postby anthonykallay » Tue, 10 Jul 2007 19:44:13 GMT

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


Re: Master page postback.. !IsPostback doesnt work

Postby UGV0ZXIgQnJvbWJlcmcgW0MjIE1WUF0 » Tue, 10 Jul 2007 20:36:01 GMT

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.**--****.com/ 
UnBlog:   http://www.**--****.com/ 
BlogMetaFinder(BETA):     http://www.**--****.com/ 







Re: Master page postback.. !IsPostback doesnt work

Postby Patrice » Tue, 10 Jul 2007 20:42:52 GMT

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]" < XXXX@XXXXX.COM > a rit dans 






Re: Master page postback.. !IsPostback doesnt work

Postby anthonykallay » Wed, 11 Jul 2007 00:49:13 GMT

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


Re: Master page postback.. !IsPostback doesnt work

Postby Patrice » Wed, 11 Jul 2007 01:06:17 GMT

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)...




 XXXX@XXXXX.COM ...



Similar Threads:

1.content page subscriber to master page event doesn't update on 2nd postback

Hello All,

Here is my issue and thanks in advance for any assistance.

I have a base page with a dropdownlist that fires an event with
the selected index. The content page catches the event and sets
a connection string to the database. The content page has a
simple gridview that should show records from the selected
database. Initial content page displays data from correct place.
first change of dropdownlist correctly updates content page
gridview. any drop down list changes after that are ineffective.
I've attempted session state index saving in conjunction with
content page and master page load events during postback and not
postback.  I've slimmed down to the basics to show my problem.


Here is the flow....

CP = Content Page
MP = Master Page

This is the first page load.  The first four things listed here
happen every page.

CP::CP                    Constructor to content page
MP::MP                    Constructor to Master page
MP::MP_Init               Master page init
CP::Page_Init             Page INIT
                          (subscribe to select change event)

CP::Page_Load:NOTPostBack Initial call to page_load
CP::GridView1_DataBound   bind it up and display records from
                          default db. this works to correct
                          database.

----------------------------------------------------------------------------------------------------
CP::Page_Load:PostBack    the first postback
MP::CSDDL_SIC FIRED       master page drop down changed by user
MP::Fire Index(1)         master fires new index to content page
CP::Catch Index(1)        content page catches
CP::GridView1_DataBound   bind it up and display records from new
                          database. this works perfectly
----------------------------------------------------------------------------------------------------
CP::Page_Load:PostBack    another post back to content page
MP::CSDDL_SIC FIRED       master page drop down changed by user
MP::Fire Index(0)         master fires new index to content page
CP::Catch Index(0)        content page catches
*****Lack of LLT::GridView1_DataBound here and on all subsequent
     dropdownlist changes*****



MASTER CODEBEHIND
public partial class MyMasterPage : MasterBase
{
   public event ConnStrChangedEventHandler ConnStrChanged;

   public MyMasterPage() {
      Debug.WriteLine(String.Format("MP::MP"));
      this.Init += new System.EventHandler(this.MyMasterPage_Init);
   }

   protected void CSDDL_SIC(object sender, EventArgs e) {
      Debug.WriteLine(String.Format("MP::CSDDL_SIC FIRED"));
      ConnStrChangedEventArgs CSCEA;
      CSCEA = new ConnStrChangedEventArgs(CSDDL.SelectedIndex);
      if (ConnStrChanged != null) {
         Debug.WriteLine(
            String.Format("MP::Fire Index({0})", CSCEA.Index));
         ConnStrChanged(this, CSCEA);
      }
   }

   private void MyMasterPage_Init(object sender, EventArgs e) {
      Debug.WriteLine(String.Format("MP::MyMasterPage_Init"));
      CSDDL.Items.Add(new ListItem("DEV1"));
      CSDDL.Items.Add(new ListItem("ATLQA"));
      CSDDL.SelectedIndex = 0;
   }
}

CP(CONTENT) CODEBEHIND
public partial class CP : System.Web.UI.Page {
   public CP() {
      Debug.WriteLine("CP::CP");
      this.Load += new System.EventHandler(Page_Load);
      this.Init += new System.EventHandler(Page_Init);
   }

   protected void Page_Init(object sender, EventArgs e) {
      Debug.WriteLine("CP::Page_Init");
      Master.ConnStrChanged += new
ConnStrChangedEventHandler(Master_ConnStrChanged);
   }

   void Master_ConnStrChanged(object sender, ConnStrChangedEventArgs e)
{
      Debug.WriteLine(String.Format("CP::Catch Index({0})", e.Index));
      SqlDataSource1.ConnectionString =
ConfigurationManager.ConnectionStrings[e.Index + 1].ConnectionString;
   }

   protected void Page_Load(object sender, EventArgs e) {
      if (IsPostBack) {
         Debug.WriteLine("CP::Page_Load:PostBack");
      }
      else {
         Debug.WriteLine("CP::Page_Load:NOTPostBack");
      }
}

ENTIRE LISTING OF MASTERPAGE.MASTER FILE
<%@ Master Language="C#"
           AutoEventWireup="true"
           CodeFile="MasterPage.master.cs"
           Inherits="MyMasterPage" %>
<html>
   <head runat="server"><title>W</title></head>
   <body>
      <form id="form1" runat="server">
         <div>
            <table>
               <tr>
                  <td>
                     <asp:contentplaceholder id="CP" runat="server" />
                  </td>
               </tr>
               <tr>
                  <td>Database</td>
                  <td>
                     <asp:DropDownList
                        ID="CSDDL"
                        runat="server"
                        AutoPostBack="True"
                        OnSelectedIndexChanged="CSDDL_SIC" />
                  </td>
               </tr>
            </table>
         </div>
      </form>
   </body>
</html>

LLT.ASPX (Content Page) stripped
<%@ Page Language="C#"
         MasterPageFile="~/MasterPage.master"
         AutoEventWireup="true"
         CodeFile="WF_STATUS.aspx.cs"
         Inherits="LLT"
         EnableSessionState="True" %>
<%@ MasterType TypeName="MyMasterPage" %>
<asp:Content ID="Content1"
             ContentPlaceHolderID="CP"
             Runat="Server">
   <div>
      <asp:GridView
         ID="GridView1"
         runat="server"
         DataSourceID="SqlDataSource1"
         OnRowDataBound="GridView1_RowDataBound"
         OnDataBound="GridView1_DataBound" />
      <asp:SqlDataSource />
   </div>
</asp:Content>

2.Cross-Page PostBack, Master page, and GridView issue in ASP.Net 2.0

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 pages.

So far, I have had success in building the search form, and passing the
values entered by the user from the form to a results page, and
displaying the entire resultset using GridView.  However, when I set
the AllowPaging option on the GridView tag to true, I get the following
error when I try to move from one GridView page to the next:

"Object reference not set to an instance of an object"

The objects that it is trying to reference, of course, are all of the
search parameters submitted on the search form which I was able to call
using the PreviousPage object.  So far, all of this makes a sort of
sense to me; I'm pretty sure I know why the PreviousPage calls fail
when Gridview is set to allow paging.

So really, my question is:  What is the best way of capturing the data
from a cross-page post back so that the values are retained in such a
way that a GridView object may be set to page its results?

3.Cross Page Post Back When Using Mixture of Master Pages and Non-Master Pages

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
Page2.aspx, which doesn't use a Master Page at all - it's just a
straight forward .aspx page. Problem is I can't seem to get the form
field values from page1.aspx in use on page2.aspx. I've set up the
PagePostBackURL attribute on the submit button on page1.aspx and have
added the PreviousPageType directive along with the virtualpath
attribute of it to page2.aspx. Help. How do I get the posted values
from the first page?

4.GridView - RowCreated EventHandler doesn't work if page IsPostBack

Hello All,

I am trying to use the following RowCreated Event Handler to make the
BackColor of a cell different if it has a particular value.

protected void GridView1_RowCreated(object sender,
GridViewRowEventArgs e)
    {
        if (e.Row.RowType == DataControlRowType.DataRow)
        {

            object cellValue = DataBinder.Eval(e.Row.DataItem,
"Primary Diagnosis");
            if(cellValue != null)
            {

                if (cellValue.Equals("Unknown or Service Recipient
Declined"))
                {
                    e.Row.Cells[1].BackColor = Color.Yellow;
                }

            }
        }
}

The page works as expected the first time it is loaded. But if it is a
PostBack cellValue is null, so the code to color the cells BackColor
does not run. If I take out condition "if(cellValue != null) I get an
error message. How can I use the RowCreated Event handler to control
the BackColor of cells even when it is a PostBack.

Help is always appreciated. Thanks,

Paul

5.My VWD Express pages won't work since adding Master page to Intran

I have a aspx site (intranet) that users can view sql data. They also use 
this site to register for things based on that data.  My sql still works, but 
my forms (postbacks) do not why?

Thanks..

6. setting page title worked, now doesnt?

7. HTTP Post Doesnt work in ASP.NET page

8. Can a master page be built from another master page



Return to ASP.NET

 

Who is online

Users browsing this forum: No registered users and 88 guest