in a 3 tier web application, how can i popluate textboxes with text on a webform from the business access layer? do i need to search for the control by name? that seems a rough way to do it.
I think the best way to populate the web form text box should not be from the business layer. Create a DTO object, populate the DTO object and use that DTO object to pupulate the text box.
You cannot access the text box control of the UI from the BAL.
There are several ways you can accomplish this, but (2) that I recommend.
1. Create custom business entities or business objects in your BLL. These custom classes will have properties on them which ultimately will be bound to different types of controls in the UI. The ide is that the UI layer calls the business logic layer to
get back a List(Of <T>), where <T> is your custom class, and then in some form is used as the datasource for your UI control.
2. The 2nd method allows a better abstraction and is less tightly coupled than the example above but is a bit more work. The idea is to create 'Views' or special classes specific for transforming business or domain objects into objects for binding and communicating
to the UI. The advantage of creating these Views is they are typically UI type agnostic which allows for greater re-use if the application needed to be ported to another application type (i.e. webforms to smart client, etc.). The MVP (Model-View-Presenter)
or DDD (Domain Driven Design) are a good variation of the 3-tier architecture that would encompass using views.
#2 above might have been more food for thought, and #1 probably makes more sense, so below is a brief example.
Namespace BLL
Public Class Employee
Public Property FirstName As String
Public Property LastName As String
Public Property ID As Integer
Public Function GetAll() As List(Of Employee)
'Code here to call DAL,Repository, etc and get all employees
End Function
End Class
End Namespace
Public Sub BindEmployees()
'Some UI method to populate a GridView using a List(Of Employee) from the BLL
Dim Employees As New List(Of BLL.Employee)
Using Emp As New Employee()
Employees = Emp.GetAll()
End Using
'Bind the GridView to the list
Me.GridView1.DataSource = Employees
End Sub
Of course the sample code is quite rudimentary and many other design principals and patterns have been omitted, but it should show you how the (2) layers interact. Hope this helps!
nmaddock123
Member
10 Points
13 Posts
how to populate textboxes from BAL
Dec 22, 2011 09:08 PM|LINK
Hi Guys,
in a 3 tier web application, how can i popluate textboxes with text on a webform from the business access layer? do i need to search for the control by name? that seems a rough way to do it.
thanks in advance
premchand_p_...
Member
2 Points
1 Post
Re: how to populate textboxes from BAL
Dec 23, 2011 04:43 AM|LINK
Hi,
I think the best way to populate the web form text box should not be from the business layer. Create a DTO object, populate the DTO object and use that DTO object to pupulate the text box.
You cannot access the text box control of the UI from the BAL.
-Premchand
nirmal.bond
Member
290 Points
92 Posts
Re: how to populate textboxes from BAL
Dec 23, 2011 05:58 AM|LINK
Hello,
You can't populate it on BAl. You can create its properties their and assisgn those properties to you textboxes at your presentation layer.
varunthedon
Member
212 Points
58 Posts
Re: how to populate textboxes from BAL
Dec 26, 2011 11:35 PM|LINK
Hi nmaddock123,
Populating textboxes from business layer is not possible.
Instead, pass it to the presentation layer and then populate it.
Best practice is as nirmal sugessted, create properties to the textboxes and pass it on to the presentation layer.
In case this answer helped you out, please mark this as Answer!
For similar issues and their solutions, refer to My Blog
Sincerely,
Varun Shringarpure
atconway
All-Star
16846 Points
2756 Posts
Re: how to populate textboxes from BAL
Dec 27, 2011 01:45 AM|LINK
There are several ways you can accomplish this, but (2) that I recommend.
1. Create custom business entities or business objects in your BLL. These custom classes will have properties on them which ultimately will be bound to different types of controls in the UI. The ide is that the UI layer calls the business logic layer to get back a List(Of <T>), where <T> is your custom class, and then in some form is used as the datasource for your UI control.
2. The 2nd method allows a better abstraction and is less tightly coupled than the example above but is a bit more work. The idea is to create 'Views' or special classes specific for transforming business or domain objects into objects for binding and communicating to the UI. The advantage of creating these Views is they are typically UI type agnostic which allows for greater re-use if the application needed to be ported to another application type (i.e. webforms to smart client, etc.). The MVP (Model-View-Presenter) or DDD (Domain Driven Design) are a good variation of the 3-tier architecture that would encompass using views.
#2 above might have been more food for thought, and #1 probably makes more sense, so below is a brief example.
Of course the sample code is quite rudimentary and many other design principals and patterns have been omitted, but it should show you how the (2) layers interact. Hope this helps!
nmaddock123
Member
10 Points
13 Posts
Re: how to populate textboxes from BAL
Dec 28, 2011 06:43 PM|LINK
thanks for your help