Multiple user conrols on a web form

S

Sam Kuehn

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!
 
G

Guest

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/b8550e4b-b8f5-4446-b065-0b19f4c739bc.dcik

Bill

Sam Kuehn said:
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!
 
K

Karl Seguin

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 said:
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!
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,774
Messages
2,569,596
Members
45,143
Latest member
SterlingLa
Top