Tuesday, February 9, 2010

Grid CausedCallback and IsCallback values are incorrect

I am using a ComponentArt grid on one of the ASP.Net pages. In the Page_Load() I have the code to load the grid. The code looks something like this...


protected void Page_Load(object sender, System.EventArgs e)
{
  if(Page.IsPostBack == false)
  {
    buildGrid();
  }
}

This works well, the buildGrid() is called only when the page is loaded for the first time and when a postback occurs the function is skiiped.

However my grid a paging enabled and grid runs at server side (runat="server"). This mean grid would postback everytime you naviage from page to page. So adding another check as follows...


protected void Page_Load(object sender, System.EventArgs e)
{
  if(Page.IsPostBack == false &&
   Grid1.CausedCallabck ==false )
  {
    buildGrid();
   }
}


This means buildGrid() is skipped when when Grid1 caused the callback (e.g. navigating from page to page within the grid).

But here is the problem. The Grid1.CausedCallback is false when you load the page for the first time and changes to true when you change pages on the grid but remain true there after. Even if you navigate away from the page that contains the grid to something totally different and come back to this page Grid1.CausedCallback remains true. This can cause many problem based on the implementation you have.

I am not sure what the problem is, it could be a bug in the component itself. I did spend sometime to figure it out but with no luck. So I decided to use a work around.

Work around:

The Request object has a property called UrlReferrer. This basically tells us from which page the request is coming to the current page. This mean when ever the UrlReferrer is otherthan current page(page with the grid) we know the user is landing on current page for the first time. So the final code looks something like this.


protected void Page_Load(object sender, System.EventArgs e)
{
  string url = Request.UrlReferrer.ToString();
  if(Page.IsPostBack == false &&
    url.ToLower().Contains("currentpagename.aspx")==false )
  {
   buildGrid();
  }
}

11 comments:

Anonymous said...

Howdy! Do you use Twitter? I'd like to follow you if that would be okay. I'm absolutely
enjoying your blog and look forward to new updates.

Also visit my homepage party poker bonus code december 2013

Anonymous said...

Fine way of describing, and good article to take information about my presentation
subject matter, which i am going to present in institution of higher education.



My web page: poker for free games

Anonymous said...

Hi, I desire to subscribe for this webpage to
obtain hottest updates, thus where can i do it please help out.


Feel free to visit my web page; partypoker bonus code 2013

Anonymous said...

Thank you for the auspicious writeup. It in fact was a amusement
account it. Look advanced to far added agreeable from you!
However, how could we communicate?

my blog post - rtg casinos bonus codes

Anonymous said...

There is certainly a lot to learn about this subject.
I really like all of the points you have made.

Also visit my blog post ... party poker bonus code

Anonymous said...

If you wish for to improve your know-how just
keep visiting this web page and be updated with the most recent news update posted here.



Feel free to surf to my web site real time gaming

Anonymous said...

Hi there everyone, it's my first pay a quick visit at this web page, and paragraph is in fact fruitful designed for me, keep up posting such posts.

Feel free to visit my web-site: rtg casinos no deposit bonus codes 2013

Anonymous said...

What's up colleagues, its wonderful piece of writing on the topic of educationand entirely explained, keep it up all the time.

My blog post: brunomars.Com

Anonymous said...

It's an amazing post designed for all the web visitors; they will obtain advantage from it I am sure.

Review my page rtg casinos usa

Anonymous said...

Write more, thats all I have to say. Literally, it seems as though you relied
on the video to make your point. You definitely know what youre talking about, why waste your intelligence on just posting videos to your site when you could be giving us something enlightening to read?



Here is my webpage Rtg Casino Bonus

Anonymous said...

smokeless cigarettes, e cig forum, electronic cigarettes, e cig, e cigarette reviews, e cigarette