Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

different between this.Page and (Page)HttpContext.Current.Handler

Tags:

asp.net

HI!

does anybody know about different between this.Page and (Page)HttpContext.Current.Handler?

i had a problem that this.page returned null, and someone wrote me that using the construct "(Page)HttpContext.Current.Handler" will be better.

  1. what the different?
  2. why and when this.page return null?

thanks!!

Shani

like image 881
Shani Avatar asked Mar 30 '11 16:03

Shani


1 Answers

this.Page will find a control's Page by searching it's parent hierarchy.

HttypContext.Current.Handler will find the page by looking at the current context (thread).

The first will be null even when the second is valid if the control hasn't been put into the page hierarchy yet.

like image 169
Samuel Neff Avatar answered Sep 27 '22 18:09

Samuel Neff