Question

I am using the session object to store success/error messages based on user actions.

On each postback, the message is set on ItemCommend and retrieved on the Page_Load of the master page. Once retrieved, the message is deleted from the session.

The problem is that the master page's Page_Load gets called before the ItemCommand gets called so the message does not show up until the next refresh or postback.

How is this situation normally handled? Is there some other event we can code against?

Was it helpful?

Solution

It is normal behavior of aspx and master pages. First of all content page's page load get fired after that Master Page's pageload get fired and then all other click etc.

You can use PageLoad Complete event to Solve your problem.

OTHER TIPS

this is a normal behavior. show your message on itemcommand or Page_prerender

Create a Public Method in Code Behind of your master page like this:

 public void Set_Value(String SessionValue)
   {
      //your code here
   }

In aspx File of your content Page, Use following Line of code:

  <%@ MasterType VirtualPath="~/MasterPage.master" %>

Now in Code Behind of your Content Page, You can easily call Master Page's method in Item event of your any Control. In your Master Page's method you can write your required code to update and show values.

Call Master Page's Method on Content Page Like this:

  this.Master.Set_Value(Session["abc"].ToString());
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top