Solved

Postback error on ASP page

Posted on 2009-04-02
6
651 Views
Last Modified: 2012-05-06
Greetings all

I am experiencing a Invalid Postback error on my page (code included under snippets).

The steps are:

1.  Browse the default page

2.  Tab to a selected month and select a day (note: if you select a day on the curretn calendar
     page, then error doesn't occur)

3.  Click the hyperlink to go to a diferent page.

4.  Click the browser's "<--" to return to the page
     At this stage, the view is that which we saw when we first browsed the page

5.  Click the "<" button on the calendar to go to the month from which I previously selected a
     date  --- POST BACK ERROR


 A few notes ...

a.  I'm using IExplorer

b.  If I press <F5> after Step2 and then proceed a normal, then it works fine

c. I am using the following code to block caching for Fox. If I apply this to IE, then it
   also works.
                           if (Request.Browser.MSDomVersion.Major == 0) // Non IE Browser?)
                              Response.Cache.SetNoStore(); // No client side cashing for non IE browsers


What am I missing? What do I need to change, to get it working without?

In advance, thanks!

    allanmark


DEFAULT PAGE SOURCE:
 
<%@ Page Language="C#" MasterPageFile="~/MimeMaster01.master" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" Title="Untitled Page" %>
 
<asp:Content ID="Content1" ContentPlaceHolderID="leftnav" Runat="Server">
 
    <ajaxext:ScriptManagerProxy ID="ScriptManagerProxy1" runat="server">
    </ajaxext:ScriptManagerProxy>
 
    <center>
    <asp:HyperLink  ID="hypContacts" runat="server" CssClass="hypLink" NavigateUrl="~/Miscellaneous/Contacts.aspx" >Contacts</asp:HyperLink>
    </center>   
    <br />    
    <br />
 
    <ajaxext:UpdatePanel ID="UpdatePanel1" runat="server">
    <ContentTemplate>
         
        <center>
        <asp:Calendar ID="calEvents" runat="server" BackColor="White" BorderColor="#999999"
            CellPadding="4" DayNameFormat="Shortest" Font-Names="Verdana" Font-Size="8pt"
            ForeColor="Black" Height="180px" Width="200px" OnSelectionChanged="calEvents_SelectionChanged">
            <SelectedDayStyle BackColor="#ffc0cb" Font-Bold="True" ForeColor="White"  />
            <TodayDayStyle BackColor="#ffc0cb" ForeColor="Black" />
            <SelectorStyle BackColor="#CCCCCC" />
            <WeekendDayStyle BackColor="#CD8C95" />
            <OtherMonthDayStyle ForeColor="#808080" />
            <NextPrevStyle VerticalAlign="Bottom" />
            <DayHeaderStyle BackColor="#ffb6c1" Font-Bold="True" Font-Size="7pt" />
            <TitleStyle BackColor="#ffc0ca" BorderColor="Black" Font-Bold="True" />
        </asp:Calendar>
        </center>
        
        <br />
        <center>
        <h5 class="h5header" >Events for the day:</h5>
        <asp:ListBox ID="lbxEvents" runat="server" CssClass="listbox"  ></asp:ListBox>
        </center>
        
    </ContentTemplate>
    </ajaxext:UpdatePanel>
    
 
</asp:Content>
 
<asp:Content ID="Content2" ContentPlaceHolderID="righnav" Runat="Server">
 
<h3>Welcome!</h3>
<p>This is the administration site of Marriage Encounter (ME) - Western Cape. Access is restricted to ME members who are a part of the administration team. If you are a team member but do not have access, please contact the Administrator (click the "Contacts" link in the left pane to be taken to our contacts page) and request the necessary clearance.</p>
<br />
<p><i>The Admin Team!</i></p>
    
</asp:Content>
 
 
 
DEFAULT PAGE CODE BEHIND:
 
using System;
using System.Data;
using System.Text;
using System.Configuration;
using System.Collections;
using System.Collections.Generic;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using BusinessLogic;
using DataTransferObjects;
 
public partial class _Default : System.Web.UI.Page
{
    private List<ME_Event> dailyEvents;
 
    private bool loggedIn;
 
    protected void Page_Load(object sender, EventArgs e)
    {
        bool needToCallEvents;
 
 
        needToCallEvents = false;
 
        if (Request.Browser.MSDomVersion.Major == 0) // Non IE Browser?)
          Response.Cache.SetNoStore(); // No client side cashing for non IE browsers
 
        // Load the Page-specific stylesheet.
        HtmlLink lnk = (HtmlLink)Master.FindControl("cssLink");
        if (lnk != null)
            lnk.Href = "~/CSS/Default.css";
 
        if (Page.IsPostBack)
        {
            if (Session["loggedIn_Session"] != null)
            {
                if ((bool)Session["loggedIn_Session"] != User.Identity.IsAuthenticated)
                {
                    loggedIn = User.Identity.IsAuthenticated;
                    Session["loggedIn_Session"] = loggedIn;
                    FetchDailyEvents();
                }
                else
                {
                    loggedIn = (bool)Session["loggedIn_Session"];
 
                    dailyEvents = (List<ME_Event>)Session["dailyEvents_Session"];
                    lbxEvents.DataSource = dailyEvents;
                    lbxEvents.DataBind();
 
                    calEvents.VisibleDate = calEvents.SelectedDate;
                }
 
            }
            else
            {
                loggedIn = User.Identity.IsAuthenticated;
                Session["loggedIn_Session"] = loggedIn;
                FetchDailyEvents();
            }
        }
        else
        {            
            // Not PostBack
            needToCallEvents = false;
 
            if (Session["loggedIn_Session"] != null)
            {
                if ((bool)Session["loggedIn_Session"] != User.Identity.IsAuthenticated)
                {
                    loggedIn = User.Identity.IsAuthenticated;
                    Session["loggedIn_Session"] = loggedIn;
                    needToCallEvents = true;
                }
                else
                {
                    loggedIn = (bool)Session["loggedIn_Session"];
                }
 
                if (Session["selectedDate_Session"] != null)
                {
                    calEvents.SelectedDate = (DateTime)Session["selectedDate_Session"];
                    calEvents.VisibleDate = calEvents.SelectedDate;
                }
                else
                {
                    calEvents.SelectedDate = calEvents.TodaysDate;
                    calEvents.VisibleDate = calEvents.SelectedDate;
                }
            }
            else
            {
                loggedIn = User.Identity.IsAuthenticated;
                calEvents.SelectedDate = calEvents.TodaysDate;
                needToCallEvents = true;
            }
 
                FetchDailyEvents();
 
 
        }
 
        
    }
 
    protected void calEvents_SelectionChanged(object sender, EventArgs e)
    {
        FetchDailyEvents();
 
    }
 
    private void FetchDailyEvents()
    {     
        lbxEvents.DataSource = "";
        dailyEvents = null;
 
        if (loggedIn)
        {
            dailyEvents = BusinessLogic.Business.GetEvents(calEvents.SelectedDate, "Y");
        }
        else
        {
            dailyEvents = BusinessLogic.Business.GetEvents(calEvents.SelectedDate, "N");
        }
 
        lbxEvents.DataSource = dailyEvents;
        lbxEvents.DataTextField = "Title";
        lbxEvents.DataValueField = "Id";
        lbxEvents.DataBind();
 
        Session["selectedDate_Session"] = calEvents.SelectedDate;
        calEvents.VisibleDate = calEvents.SelectedDate;
 
        Session["dailyEvents_Session"] = dailyEvents;
    }
 
}
 
 
MASTER PAGE SOURCE:
 
<%@ Master Language="C#" AutoEventWireup="true" CodeFile="MimeMaster01.master.cs" Inherits="MimeMaster01" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
 
<html xmlns="http://www.w3.org/1999/xhtml" >
 
<head id="Head1" runat="server">
    
    <title>Mime Master</title>
    
     <link id="cssLink" rel="stylesheet" type="text/css" runat="server"
    href="CSS/Mime.CSS" />  
    
</head>
 
<body id="MasterBody" runat="server" >
 
<form id="form1" runat="server" style="height: 100%;">
    
<div id="container" >
 
    <a name="theTop" ></a>  
    
	<div id="header">
	<!-- Header start -->		  
          		  
		  <ajaxext:ScriptManager ID="scriptmanager1" runat="server">
          </ajaxext:ScriptManager>          
          
          <asp:LoginName  ID="lgUser" runat="server" CssClass="loginName" FormatString="Member: {0}"/>
          
          <center>
		  <h1>Marriage Encounter - Western Cape</h1>
		  <h5>(Administration Management)</h5>
          </center>
          
          <asp:Label ID="lblFollowup" runat="server" CssClass="followup" Visible="false">** Follow-ups Outstanding **</asp:Label>
                         
          <asp:Image ID="headerPict" runat="server" CssClass="headerPic" ImageUrl="~/Graphics/ME05.Gif" />
 
          <center><ul id='menu' style="width: 67%">
                <li ><a href='<%=ResolveUrl("Default.aspx")%>'  id='menuHome' >Home</a></li>
                <li ><a href='<%=ResolveUrl("Default2.aspx")%>' id='menuPeople' >People</a></li>
                <li ><a href='<%=ResolveUrl("Default2.aspx")%>' id='menuCircles' >Circles</a></li>
                <li ><a href='<%=ResolveUrl("Default2.aspx")%>' id='menuWeekends' >Weekends</a></li>
                <li ><a href='<%=ResolveUrl("Default2.aspx")%>' id='menuEvents' >Events</a></li>
                <li ><a href='<%=ResolveUrl("Default2.aspx")%>' id='menuGeneral' >General</a></li>
                <li ><a href='<%=ResolveUrl("Default2.aspx")%>' id='menuPortfolios' >Portfolio</a></li>
                <li ><a href='<%=ResolveUrl("Default2.aspx")%>' id='menuUsers' >Users</a></li>
              </ul>
              
              <asp:LoginStatus ID="logOn" runat="server" CssClass="loginStat" />              
            <!-- Give a little space -->
            <div style="height:15px"></div>
 
              <hr  width="96%" class="redline"/>
          </center>
 
          
	<!-- Header end -->
	</div>
	
	<div id="body">
    <!-- Body start -->
    
	    <div id="dummy" style="position:relative; height: 40px"></div>
		
        <div id="wrapperDiv" class="wrapper"> 	
	  
	    <div id="left" class="leftnav">	
		       <asp:ContentPlaceHolder ID="leftnav" runat="server">
                </asp:ContentPlaceHolder>
        </div>
        
        <div id="right" class="rightnav">	
              <asp:ContentPlaceHolder ID="righnav" runat="server">
              </asp:ContentPlaceHolder>
        </div>
      
      <!-- <div id="wrapper"> 	 -->
      </div>
        
        <!-- Give a little space -->
        <div style="height:45px"></div>
        
    <!-- Body end -->
	</div>
	
	<div id="footer">
	<!-- Footer start -->
	
		  <center><hr width="75%" class="redline" /></center>
		  
		  <!-- Give a little space -->
          <div style="height:10px"></div>
		  
		  <center><a href="#theTop" class="anchor"  >Back to top</a></center>
		  
		  <br />
          <center>Marriage Encounter Western Cape &reg; is a registered trademark of Marriage Encounter Western Cape, Inc<br />
          &copy; 2009 Marriage Encounter Western Cape, Inc.
          </center>            
        
	<!-- Footer end -->
	</div>    
 
<!-- Div: "Container"  end -->
</div>
 
</form>
 
</body>
 
</html>
 
 
MASTER PAGECODE BEHIND:
 
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
 
public partial class MimeMaster01 : System.Web.UI.MasterPage
{
    protected void Page_Load(object sender, EventArgs e)
    {
 
    }
 
 
}

Open in new window

0
Comment
Question by:allanmark
  • 3
  • 3
6 Comments
 
LVL 26

Expert Comment

by:Rejojohny
ID: 24055104
what is the postback error and why are you posting back when changing month in the calendar?
0
 

Author Comment

by:allanmark
ID: 24057199
Hi!

Please attached snippet fro PostBack error.

As to why posting back on month change - it wasn't something that I planned to do - it just "happens" (admittedly, most likely because I have done something wrong).
PB-Error.jpg
0
 
LVL 26

Expert Comment

by:Rejojohny
ID: 24059560
the postback happens because you have a event attached to selectedindexchanged
OnSelectionChanged="calEvents_SelectionChanged"

if you do not want any processing to be done when the date/month/year etc is changed, remove that piece of code

As far as the error is concerned, do what it suggests. one of the option mentioned is to add enableEventvalidation attribute to the page. So in the aspx page at the top i.e "<%@page" section, add
<%@page enableEventValidation="false" .....
OR use the other option mentioned, which is  to register your event ..


Rejo
0
VMware Disaster Recovery and Data Protection

In this expert guide, you’ll learn about the components of a Modern Data Center. You will use cases for the value-added capabilities of Veeam®, including combining backup and replication for VMware disaster recovery and using replication for data center migration.

 

Author Comment

by:allanmark
ID: 24060924
I'm happy with what you're saying.

What confuses me is why when I "<--" to go back to the page, it isn't displaying the data as it was before the hyperlink was clicked. If I click teh <F5> , it  then goes back into the Page_Load, is not a PostBack and follows that code route. It then diisplays the data as it shoudl be and I can happily go to any other month.

Also, if after goin to the pevious month and selecting, I then hit <F5> and therafter do the Hyperlink thingy and "<---" thingy, then it all works fine.

Obviously, this is telling me something, but I'm not sure what?
0
 
LVL 26

Accepted Solution

by:
Rejojohny earned 375 total points
ID: 24063258
>>What confuses me is why when I "<--" to go back to the page, it isn't displaying the data as it was before the hyperlink was clicked
Because you have everytihng witihin updatepanels (AJAX), the partial postbacks of the page is not cached by the browser. So when you go back to a page which had a partial postback earlier, the changed values will not be seen because the browser cache just has the content that was stored when the page was first shown

Rejo
0
 

Author Closing Comment

by:allanmark
ID: 31565685
Now I understand!! Thanks!! NAd thanks for your patience!!
0

Featured Post

Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

The Confluence of Individual Knowledge and the Collective Intelligence At this writing (summer 2013) the term API (http://dictionary.reference.com/browse/API?s=t) has made its way into the popular lexicon of the English language.  A few years ago, …
Introduction A frequently asked question goes something like this:  "I am running a long process in the background and I want to alert my client when the process finishes.  How can I send a message to the browser?"  Unfortunately, the short answer …
This tutorial gives a high-level tour of the interface of Marketo (a marketing automation tool to help businesses track and engage prospective customers and drive them to purchase). You will see the main areas including Marketing Activities, Design …
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…

770 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question