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

Multiple user conrols on a web form

P: n/a
I have been stuck on this for some time and am desperate for a solution. I run into this all of the time! I will give a over simplified example to illustrate the problem. Say you have 2 user controls on a web form. One for inputing data (like a line item to an order) and one to display the detail data (a data grid with all line items the order). So, you input data into the input form, then click the add button. The from in posted back. Naturally you would want the newly added line to show up in the detail user control when the form is refreshed. The problem is it probably will not. Why? Because the event handler for the add button will be called after the data grid (or repeater whatever) has been bound (Assuming you are doing the data binding for the grid in the Page_Load event handler of the detail control). So basically the detail grid is created and THEN the line is added. In this simple situation you could probably work around it (Response.Redirect back to itself but then you loose view state which in undesirable). As you can imagine the problem gets quite complicated when you have many many user controls on a page. What is the answer to this? Is my architecture fundamentally flawed and this structure is no good? HELP!
Nov 18 '05 #1
Share this Question
Share on Google+
3 Replies


P: n/a
Sam, when you want an update event to affect the output, put the output in
Page Prerender (happens after the event is processed) instead of Page Load
(happens before the event is processed, as you know). Check out this article:
http://dotnetjunkies.com/tutorial/b8...9f4c739bc.dcik

Bill

"Sam Kuehn" wrote:
I have been stuck on this for some time and am desperate for a solution. I run into this all of the time! I will give a over simplified example to illustrate the problem. Say you have 2 user controls on a web form. One for inputing data (like a line item to an order) and one to display the detail data (a data grid with all line items the order). So, you input data into the input form, then click the add button. The from in posted back. Naturally you would want the newly added line to show up in the detail user control when the form is refreshed. The problem is it probably will not. Why? Because the event handler for the add button will be called after the data grid (or repeater whatever) has been bound (Assuming you are doing the data binding for the grid in the Page_Load event handler of the detail control). So basically the detail grid is created and THEN the line is added. In this simple situation you could probably work around it (Response.Redirect back to itself but then you loose view state which in undesirable). As you can imagine the problem gets quite complicated when you have many many user controls on a page. What is the answer to this? Is my architecture fundamentally flawed and this structure is no good? HELP!

Nov 18 '05 #2

P: n/a
The solution is easy, and you have two options. First, when the click event
of the user control fires, add the row then call a "rebind" method from the
other user control to rebind the data, something like:

public class detailData
public Page_Load
if not page.ispostback then
RebindData()
end if
end
public RebindData
datalist.DataSoure = GetData()
datalist.DataBind
end
...
end class
public class MainPage
public details as detailData 'user control has an id of "details"
obviously
...
end class

public class InputData
public OnClick
AddNewData()
Ctype(Page, MainPage).details.RebindData()
end
..
end class
A much better solution is to have InputData raise an event which detailData
can listen to and rebind itself...You can find out more about these at:
http://openmymind.net/communication/index.html

Karl

--
MY ASP.Net tutorials
http://www.openmymind.net/
"Sam Kuehn" <sa******@hotmail.com> wrote in message
news:u5**************@TK2MSFTNGP09.phx.gbl...
I have been stuck on this for some time and am desperate for a solution.

I run into this all of the time! I will give a over simplified example to
illustrate the problem. Say you have 2 user controls on a web form. One
for inputing data (like a line item to an order) and one to display the
detail data (a data grid with all line items the order). So, you input data
into the input form, then click the add button. The from in posted back.
Naturally you would want the newly added line to show up in the detail user
control when the form is refreshed. The problem is it probably will not.
Why? Because the event handler for the add button will be called after the
data grid (or repeater whatever) has been bound (Assuming you are doing the
data binding for the grid in the Page_Load event handler of the detail
control). So basically the detail grid is created and THEN the line is
added. In this simple situation you could probably work around it
(Response.Redirect back to itself but then you loose view state which in
undesirable). As you can imagine the problem gets quite complicated when
you have many many user controls on a page. What is the answer to this? Is
my architecture fundamentally flawed and this structure is no good? HELP!
Nov 18 '05 #3

P: n/a
Great Aricatle thanks! I have began implamenting the soltion in the aritcale.
The solution is easy, and you have two options. First, when the click
event of the user control fires, add the row then call a "rebind"
method from the other user control to rebind the data, something like:

public class detailData
public Page_Load
if not page.ispostback then
RebindData()
end if
end
public RebindData
datalist.DataSoure = GetData()
datalist.DataBind
end
...
end class
public class MainPage
public details as detailData 'user control has an id of "details"
obviously
...
end class
public class InputData
public OnClick
AddNewData()
Ctype(Page, MainPage).details.RebindData()
end
..
end class
A much better solution is to have InputData raise an event which
detailData can listen to and rebind itself...You can find out more
about these at: http://openmymind.net/communication/index.html

Karl

"Sam Kuehn" <sa******@hotmail.com> wrote in message
news:u5**************@TK2MSFTNGP09.phx.gbl...
I have been stuck on this for some time and am desperate for a
solution.

I run into this all of the time! I will give a over simplified example
to illustrate the problem. Say you have 2 user controls on a web
form. One for inputing data (like a line item to an order) and one to
display the detail data (a data grid with all line items the order).
So, you input data into the input form, then click the add button.
The from in posted back. Naturally you would want the newly added line
to show up in the detail user control when the form is refreshed. The
problem is it probably will not. Why? Because the event handler for
the add button will be called after the data grid (or repeater
whatever) has been bound (Assuming you are doing the data binding for
the grid in the Page_Load event handler of the detail control). So
basically the detail grid is created and THEN the line is added. In
this simple situation you could probably work around it
(Response.Redirect back to itself but then you loose view state which
in undesirable). As you can imagine the problem gets quite
complicated when you have many many user controls on a page. What is
the answer to this? Is my architecture fundamentally flawed and this
structure is no good? HELP!


Nov 18 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.