Profilo di Ashish"Getting better never st...FotoBlogElenchiAltro Strumenti Guida

Blog


15 agosto

Accessing user control's control from the ASPX page‏

 

Ok, I know, I know! ?This is something you must be wondering like "Why this guy is so scre*** up and he had to blog about this". But I got into this problem last week and an realized that I have seen this problem and addressed this ..but just forgot about. So why not just blog about this. At least for myself :-). So, forgive me folks!!

Using user control from the ASPX page:-

The goal was to access the user control’s control from the ASPX page. First I started looking into why that control in the user control wont be available in the page load of the ASPX page. I could have debugged it. But I thought enabling tracing in and looking into the traces would be a better idea. So I added the trace switch in the web.config (I could have done this on that page itself, but I just did that in the Web.config.). I use the following tag in the Web.config under <System.Web>:-

<trace enabled=”true” pageOutput=”true”/>

clip_image002

Then I put the some Trace.Write statement in the Page_Load of the user control. Notice this is the method where the menu control is getting created (getting populated with the child control). I put the Trace.Write statement at the end of the Page_Load event handler.

clip_image004

I put the Trace.Write statement in the Page_Load of the ASPX page as well at the end.

clip_image006

Now, when I try accessing the aspx page, It would give all the tracing information right from “PreInIt” to “Render” along with all the information on the controls on this page.

Notice that the Trace.Write statement from the user control is after the same from the ASPX page which implies that the page load of the user control is fired after the page_load of the ASPX page and hence the user control’s control collection wont be available in the aspx page.

clip_image008

Now, there is another event named Page_PreRender which fires after the page load and you can tweak the controls before thry get Rendered to the page. You can override that event handler as given below.

Notice that in the below screenshot the user control’s(UserStatus1) control(userMenu) is being accessed and is getting modified. To show that this would work, there is a Trace.Write right at the end of the end of this event handler.

clip_image010

See the Trace.Write statement (highlighted) in between the Begin PreRender and End PreRender.

clip_image012

Commenti

Attendere...
Il commento immesso è troppo lungo. Immetti un commento più breve.
Immissione non effettuata. Riprova.
Impossibile aggiungere il commento al momento. Riprova più tardi.
Per aggiungere un commento è necessaria l'autorizzazione di un genitore. Chiedi autorizzazione
I tuoi genitori hanno disattivato i commenti.
Impossibile eliminare il commento al momento. Riprova più tardi.
Hai raggiunto il numero massimo di commenti pubblicabili giornalmente. Riprova tra 24 ore.
Impossibile lasciare commenti. La funzionalità è stata disattivata perché i sistemi hanno rilevato una possibile attività di spamming dal tuo account. Se ritieni che il tuo account è stato disattivato per errore, contatta il supporto tecnico di Windows Live.
Esegui il seguente controllo di protezione per completare la pubblicazione del commento.
I caratteri digitati nel controllo di protezione devono corrispondere ai caratteri dell'immagine o della riproduzione audio.

Per aggiungere un commento, accedi con il tuo Windows Live ID (se utilizzi Hotmail, Messenger o Xbox LIVE possiedi già un Windows Live ID). Accedi


Non hai ancora un Windows Live ID? Registrati

Riferimenti

L'URL di riferimento per questo intervento è:
http://ashishrocks.spaces.live.com/blog/cns!BED6CE34F24CB429!284.trak
Blog che fanno riferimento a questo intervento
  • Nessuno