Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > ASP .Net Building Controls > .ascx UserControl Properties are set after Page_Load only on PostBacks

Reply
Thread Tools

.ascx UserControl Properties are set after Page_Load only on PostBacks

 
 
Douglas J. Badin
Guest
Posts: n/a
 
      10-13-2003
I wanted to have a hierarchical DataGrid so I created a User Control that
has a DataGrid to act as the Child Grid. I put it inside a pageable Parent
Grid with a page size of one as below in Parent.aspx.

<%@ Register Tagprefix="ABC" Tagname="ChildDataGrid" Src="ucChild.ascx" %>

<ASPATAGRID
id="dgParent"
runat="server"
showfooter="true"
allowpaging="true"
pagesize="1"
OnPageIndexChanged="dgParent_PageIndexChanged"
datakeyfield="PK"
datamember="Parent"
datasource="<%# DataSet1 %>"
>

<COLUMNS>
<ASP:TEMPLATECOLUMN runat="server" headertext="">
<ITEMTEMPLATE>

....

<ABC:ChildDataGrid
id="ucChild1"
runat="server"
FK='<%# Convert.ToInt32(DataBinder.Eval(Container, "DataItem.PK")) %>'
/>

....

</ITEMTEMPLATE>
</ASP:TEMPLATECOLUMN>
</COLUMNS>
</ASPATAGRID>

I have properties, "FK" for the User Control (ucChild.ascx) that hold the
values of the relationship between the Parent and Child Grid. These are
assigned in the Parent.aspx

Initially, I DataBind the ParentDataGrid, which sets the properties of the
User Control and then the Page_Load in the UserControl DataBinds the Child
as follows

1 - Parent.aspx.cs: Page_Load: ParentDataGrid.DataBind()
2 - ucChild.ascx.cs: Properties are set because values are assigned to the
"ucChild1" attributes in the Parent.aspx
3 - ucChild.ascx.cs: Page_Load: ChildDataGrid.DataBind()

No problems so far.

Paging in the Parent Control causes a Page_Load with PostBack to the Parent
Page and User Control. It then fires the PageIndexChanged event which sets
the CurrentPageIndex and re-binds the Parent. This causes another Page_Load
in the User Control which is also viewed as a Post Back and then the
properties of the User Control are set.

1 - Parent.aspx.cs: Page_Load with PostBack
2 - ucChild.ascx.cs; Page_Load with PostBack
3 - Parent.aspx.cs: dgParent_PageIndexChanged: Set CurrentPageIndex
4 - ucChild.ascx.cs: Page_Load with PostBack: ChildDataGrid.DataBind()
5 - ucChild.ascx.cs: Properties are set because values are assigned to the
"ucChild1" attributes in the Parent.aspx

PROBLEM: In the Life-Cycle, the properties were set after the Page_Load on a
PostBack.

For now I have put the ucChild.ascx.cs PostBack code in the PreRender and
things seem to be working.

QUESTION 1: Maybe I should add a RaisePostBackEvent and do it there?

QUESTION 2: Why the difference of when the ucChild.ascx.cs properties are
set depending on PostBack or not?

Thanks,
Doug


 
Reply With Quote
 
 
 
 
Yan-Hong Huang[MSFT]
Guest
Posts: n/a
 
      10-14-2003
Hello Douglas,

Looking at the nature of this issue, I would highly recommend you contact
Microsoft Product Support Services since it would require intensive
troubleshooting which would be done quickly and effectively with direct
assistance from a Microsoft Support Professional.

Microsoft support home page: http://support.microsoft.com.

To view support options:
http://support.microsoft.com/default...d=sz;en-us;top.

To submit an online request:
http://support.microsoft.com/default...incidentsubmit.

Thanks very much.

Best regards,
Yanhong Huang
Microsoft Online Partner Support

Get Secure! ¨C www.microsoft.com/security
This posting is provided "AS IS" with no warranties, and confers no rights.

--------------------
!From: "Douglas J. Badin" <>
!Subject: .ascx UserControl Properties are set after Page_Load only on
PostBacks
!Date: Mon, 13 Oct 2003 12:31:25 -0400
!Lines: 79
!X-Priority: 3
!X-MSMail-Priority: Normal
!X-Newsreader: Microsoft Outlook Express 6.00.2800.1158
!X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1165
!Message-ID: <#>
!Newsgroups: microsoft.public.dotnet.framework.aspnet.buildingc ontrols
!NNTP-Posting-Host: fll-vodsl60-cust180.mpowercom.net 208.57.60.180
!Path: cpmsftngxa06.phx.gbl!TK2MSFTNGP08.phx.gbl!TK2MSFTN GP11.phx.gbl
!Xref: cpmsftngxa06.phx.gbl
microsoft.public.dotnet.framework.aspnet.buildingc ontrols:7746
!X-Tomcat-NG: microsoft.public.dotnet.framework.aspnet.buildingc ontrols
!
!I wanted to have a hierarchical DataGrid so I created a User Control that
!has a DataGrid to act as the Child Grid. I put it inside a pageable Parent
!Grid with a page size of one as below in Parent.aspx.
!
!<%@ Register Tagprefix="ABC" Tagname="ChildDataGrid" Src="ucChild.ascx" %>
!
!<ASPATAGRID
! id="dgParent"
! runat="server"
! showfooter="true"
! allowpaging="true"
! pagesize="1"
! OnPageIndexChanged="dgParent_PageIndexChanged"
! datakeyfield="PK"
! datamember="Parent"
! datasource="<%# DataSet1 %>"
!>
! <COLUMNS>
! <ASP:TEMPLATECOLUMN runat="server" headertext="">
! <ITEMTEMPLATE>
!
!...
!
! <ABC:ChildDataGrid
! id="ucChild1"
! runat="server"
! FK='<%# Convert.ToInt32(DataBinder.Eval(Container, "DataItem.PK")) %>'
! />
!
!...
!
! </ITEMTEMPLATE>
! </ASP:TEMPLATECOLUMN>
! </COLUMNS>
!</ASPATAGRID>
!
!I have properties, "FK" for the User Control (ucChild.ascx) that hold the
!values of the relationship between the Parent and Child Grid. These are
!assigned in the Parent.aspx
!
!Initially, I DataBind the ParentDataGrid, which sets the properties of the
!User Control and then the Page_Load in the UserControl DataBinds the Child
!as follows
!
!1 - Parent.aspx.cs: Page_Load: ParentDataGrid.DataBind()
!2 - ucChild.ascx.cs: Properties are set because values are assigned to the
!"ucChild1" attributes in the Parent.aspx
!3 - ucChild.ascx.cs: Page_Load: ChildDataGrid.DataBind()
!
!No problems so far.
!
!Paging in the Parent Control causes a Page_Load with PostBack to the Parent
!Page and User Control. It then fires the PageIndexChanged event which sets
!the CurrentPageIndex and re-binds the Parent. This causes another
Page_Load
!in the User Control which is also viewed as a Post Back and then the
!properties of the User Control are set.
!
!1 - Parent.aspx.cs: Page_Load with PostBack
!2 - ucChild.ascx.cs; Page_Load with PostBack
!3 - Parent.aspx.cs: dgParent_PageIndexChanged: Set CurrentPageIndex
!4 - ucChild.ascx.cs: Page_Load with PostBack: ChildDataGrid.DataBind()
!5 - ucChild.ascx.cs: Properties are set because values are assigned to the
!"ucChild1" attributes in the Parent.aspx
!
!PROBLEM: In the Life-Cycle, the properties were set after the Page_Load on
a
!PostBack.
!
!For now I have put the ucChild.ascx.cs PostBack code in the PreRender and
!things seem to be working.
!
!QUESTION 1: Maybe I should add a RaisePostBackEvent and do it there?
!
!QUESTION 2: Why the difference of when the ucChild.ascx.cs properties are
!set depending on PostBack or not?
!
!Thanks,
!Doug
!
!
!

 
Reply With Quote
 
 
 
 
Sreenath Madyastha
Guest
Posts: n/a
 
      10-14-2003
Hey

Thats very easy.,

Use event handlers. you implement event handlres in the user controls.
Subscribe to that in the page where u added the usercontrol.

So u fire the event in the user control automatically u can call method
in the page. And you can control the method calls.


hope u got it.

Regards

Sreenath



*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
 
Reply With Quote
 
Douglas J. Badin
Guest
Posts: n/a
 
      10-14-2003
Hi Sreenath,

If I understand you correctly you are talking about communication in the
other direction, the User Control calling the Hosting Page. My issue is the
Hosting Page setting User Control Properties, not the User Control setting
Hosting Page Properties.

My problem is a Page Life Cyle issue and where properties are set in that
cycle. The hosting page is setting properties in the User Control via the
User Control html tag attributes. Sometimes the properties are set before
the User Control Page_Load and sometimes after the User Control Page_Load
depending on whether it is a PostBack or not. Not at all consistent which
is why I am trying to get a better understanding of why so I can avoid
future problems.

Thanks,
Doug


"Sreenath Madyastha" <> wrote in message
news:...
> Hey
>
> Thats very easy.,
>
> Use event handlers. you implement event handlres in the user controls.
> Subscribe to that in the page where u added the usercontrol.
>
> So u fire the event in the user control automatically u can call method
> in the page. And you can control the method calls.
>
>
> hope u got it.
>
> Regards
>
> Sreenath
>
>
>
> *** Sent via Developersdex http://www.developersdex.com ***
> Don't just participate in USENET...get rewarded for it!



 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
modalpopupextender containing usercontrol which does its own postbacks ujjc001 ASP .Net 0 07-25-2007 08:51 PM
AJAX - Partial Postbacks are now Full Postbacks ?!! gregfocker@earthlink.net ASP .Net 0 01-25-2007 07:04 AM
Materpage page_load event fired after content page_load? rockdale ASP .Net 1 11-16-2006 06:59 PM
in VB.NET Page_load of a base class called after the derived class Page_load ? z. f. ASP .Net 0 10-19-2004 12:01 PM
page_load is fired AFTER other properties and functions are called on control - WHY? Richard Murphy ASP .Net Web Controls 0 08-07-2003 08:42 AM



Advertisments