By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
449,015 Members | 1,023 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 449,015 IT Pros & Developers. It's quick & easy.

IsPostBack Sequencing problem in dynamically created controls on web page

P: n/a
Hi Friends !!

I am facing problem in controlling the dynamically created
controls on web page. The problem Scenario is

Scenario:- My requirement is to load the web user controls on the web
page dynamically. To do this, First I including a web page
(MainPage.aspx) and I made form tag to Runat=Server. I included one
table tag and also made this table Runat=Server side. Second I created
three Web User Controls e.g. wucCustomerInfo.ascx,
wucOrderSpecifications.ascx and wucOrderDetails.ascx.

Now on the page_load of MainPage.aspx.vb, I am creating the table rows
dynamically and loading the controls in the following sequence (i)
wucCustomerInfo.ascx (ii) wucOrderSpecifications.ascx (iii)
wucOrderDetails.ascx. NOTE: I removed the <Form> tag from each web
user control.

For you reference, this code is working fine as it is loading the
controls in the same sequence and showing the contents of each
controls with the required data. Now problem comes,

Problem:-

(1) My first problem is that, whenever I click any button of either
MainPage.aspx or any web user control then it is executing PostBack of
MainPage.aspx and web user controls in the same sequence as it is
loading. What I want is if I click on any button of say
"wucOrderSpecifications.ascx" control then it should Execute the
PostBack of this control and should execute NotPostBack of all the
controls. Is there any way to do this?

(2) If I dynamically load the controls in MainPage.aspx under
NotPostBack... e.g.

'-- MainPage.aspx
If Not(IsPostBack) Then
' Load Controls Dynamically
End If

and If I click on any of the button on any web user control then the
next time controls are not coming.

Any help would be highly appreciated.

Kamal Jeet Singh !!
Nov 18 '05 #1
Share this Question
Share on Google+
1 Reply


P: n/a
Hi,

First off, if you add the controls dynamically you should add them
regardless of the Page.IsPostBack value - there is nothing in the page class
to persist them and readd them for you. Also, the best place to load them
(it's my own preference) is the Page_Init handler.

Second (regarding your first question), you'd better move the initialization
code for the controls (the code in the controls' classes) to another method
instead of the Page_Load method. If you need to pass some parameters it will
be best to create a public method that takes these parameters and call this
method after instantiating the control in the Page class. If your controls
don't need such parameter(s) you can put this code in the Init handler.
Then, some things will get persisted for you in the ViewState, some you will
have to reset on each control creation (e.g. the text properties of the
labels will be persisted for you, but if you dynamically add new controls or
handlers to events you will have to readd these every time).

Hope this helps
Martin
"Kamal Jeet Singh" <kj****@gmail.com> wrote in message
news:34**************************@posting.google.c om...
Hi Friends !!

I am facing problem in controlling the dynamically created
controls on web page. The problem Scenario is

Scenario:- My requirement is to load the web user controls on the web
page dynamically. To do this, First I including a web page
(MainPage.aspx) and I made form tag to Runat=Server. I included one
table tag and also made this table Runat=Server side. Second I created
three Web User Controls e.g. wucCustomerInfo.ascx,
wucOrderSpecifications.ascx and wucOrderDetails.ascx.

Now on the page_load of MainPage.aspx.vb, I am creating the table rows
dynamically and loading the controls in the following sequence (i)
wucCustomerInfo.ascx (ii) wucOrderSpecifications.ascx (iii)
wucOrderDetails.ascx. NOTE: I removed the <Form> tag from each web
user control.

For you reference, this code is working fine as it is loading the
controls in the same sequence and showing the contents of each
controls with the required data. Now problem comes,

Problem:-

(1) My first problem is that, whenever I click any button of either
MainPage.aspx or any web user control then it is executing PostBack of
MainPage.aspx and web user controls in the same sequence as it is
loading. What I want is if I click on any button of say
"wucOrderSpecifications.ascx" control then it should Execute the
PostBack of this control and should execute NotPostBack of all the
controls. Is there any way to do this?

(2) If I dynamically load the controls in MainPage.aspx under
NotPostBack... e.g.

'-- MainPage.aspx
If Not(IsPostBack) Then
' Load Controls Dynamically
End If

and If I click on any of the button on any web user control then the
next time controls are not coming.

Any help would be highly appreciated.

Kamal Jeet Singh !!

Nov 18 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.