473,403 Members | 2,338 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,403 software developers and data experts.

Access control on a page from inside an external class

I have a class I am creating for data access. I need to access controls from
inside the class that are on a particular page. How do I do this? or is
creating an instance of the page class and using FindControl the only way to
do it?

Jun 27 '08 #1
7 2275
Hi Andy,
It is not a good practice to add some UI code in your data layer. Normally
we write the Data Access layer to abstract the database related code from
business and Presentation layer code.

Instead i would suggest you to write parameterized methods in your data
layer and make an object of this class in business/UI layer and then call
these methods from there.

for example you can have a method that authenticates user so you can do it
this way:

In data layer:

Public function AuthenticateUser(ByVal userName as string, ByVal password as
string) As boolean

'Make the Db call here and then return the result as true/false depending on
whether you got a row for the given username-password or not.

End function

Please let me know if it worked for you.else send me the code that you are
writing.

regards,
Joy

"Andy B" wrote:
I have a class I am creating for data access. I need to access controls from
inside the class that are on a particular page. How do I do this? or is
creating an instance of the page class and using FindControl the only way to
do it?

Jun 27 '08 #2
I would have at least 8 or so UI controls that the class would need to have
access to. Is this an unusual amount of parameters? I was possibly thinking
of sending a collection of controls but not for sure if that will work or
not...
"Joy" <Jo*@discussions.microsoft.comwrote in message
news:A3**********************************@microsof t.com...
Hi Andy,
It is not a good practice to add some UI code in your data layer. Normally
we write the Data Access layer to abstract the database related code from
business and Presentation layer code.

Instead i would suggest you to write parameterized methods in your data
layer and make an object of this class in business/UI layer and then call
these methods from there.

for example you can have a method that authenticates user so you can do it
this way:

In data layer:

Public function AuthenticateUser(ByVal userName as string, ByVal password
as
string) As boolean

'Make the Db call here and then return the result as true/false depending
on
whether you got a row for the given username-password or not.

End function

Please let me know if it worked for you.else send me the code that you are
writing.

regards,
Joy

"Andy B" wrote:
>I have a class I am creating for data access. I need to access controls
from
inside the class that are on a particular page. How do I do this? or is
creating an instance of the page class and using FindControl the only way
to
do it?


Jun 27 '08 #3
Hi Andy,
I would have been better equipped to help you, had i been aware of your
business scenario.

However, if you have more than 3 control's value to be passed as parameter
then i would suggest you to create a Parameter class. The following example
will make the suggestion more clear for you:

Suppose you had to design an Customer registration page.
Suppose it had the following text fields:
1. Name
2. Age
3. City
4. Country
5. Language
6. Phone
7. Fax

You can write a Customer class that has the following private members and
should also be supported by getter/setter properties for each of the private
members:

Public Class Customer
{
Private string strName ;
Private string strAge;
Private string strCity;
Private string strCountry;
Private string strLanguage;
Private string strPhone;
Private string strFax;

//Getter/Setter properties will follow here
public string Name
{
get
{
return strName ;
}
set
{
strName = value;
}
}

}

Then write the Data layer methods as such that they accept Customer class
object as parameters.
In the UI layer first make a Customer object and then initialise all its
properties with control's values and then make an object of the data layer
and call the DB method on this object thereby passing it the Customer object
as parameter.

Please let me know if this worked for you.

regards,
Joy

"Andy B" wrote:
I would have at least 8 or so UI controls that the class would need to have
access to. Is this an unusual amount of parameters? I was possibly thinking
of sending a collection of controls but not for sure if that will work or
not...
"Joy" <Jo*@discussions.microsoft.comwrote in message
news:A3**********************************@microsof t.com...
Hi Andy,
It is not a good practice to add some UI code in your data layer. Normally
we write the Data Access layer to abstract the database related code from
business and Presentation layer code.

Instead i would suggest you to write parameterized methods in your data
layer and make an object of this class in business/UI layer and then call
these methods from there.

for example you can have a method that authenticates user so you can do it
this way:

In data layer:

Public function AuthenticateUser(ByVal userName as string, ByVal password
as
string) As boolean

'Make the Db call here and then return the result as true/false depending
on
whether you got a row for the given username-password or not.

End function

Please let me know if it worked for you.else send me the code that you are
writing.

regards,
Joy

"Andy B" wrote:
I have a class I am creating for data access. I need to access controls
from
inside the class that are on a particular page. How do I do this? or is
creating an instance of the page class and using FindControl the only way
to
do it?



Jun 27 '08 #4
Hi Joy,

Sorry it took so long to get back to you on this subject. I haven't tried
your idea yet, but it is an interesting idea for some other part of the
project possibly. I don't think this will work directly for this particular
problem. Here is in some more detail of what I need to do, now that I have
clearance to do so. On this particular page, there is a wizard control that
has 7 different steps to it. In step 1, there are the following controls:
1. ContractHeaderDirectionsLabel - Gives directions for step 1 of the
wizard.
2. ContractTitleTextBox - A textbox that will contain a title for the
created contract (entered by user).
3. ContractTitleTextBoxCounter - A custom built control that counts the
words/characters in the ContractTitleTextBox.
4. ContractTypeTextBox - A textbox that will contain the type of contract
being created (entered by user).
5. ContractTypeTextBoxCounter - A custom built control that counts the
words/characters in the ContractTypeTextBox.
6. HeaderActionButton - A LinkButton that when pressed, either initially
saves or saves changes in the contract header depending on the state of the
wizardStep.

The different "states" of the wizard step are:
1. Default- shows the wizard in a state where the contract header has never
been created before. The HeaderActionButton above would have a Text value of
"Save header" and a CommandName value of "FirstSave".
2. Preview mode where the HeaderActionButton above has the TextValue of
"Edit header" and a CommandName of "EditHeader". In this mode, the 2
textboxes above (ContractType and ContractTitle) would be changed to
readonly, the 2 TextBoxCounters would be made to be invisible and the
ContractHeaderDirectionsLabel would be changed to display a new set of
directions.
3. EditMode - This mode would have the HeaderActionButton Text value set to
"Save changes" and the CommandName set to "SaveChanges". In this mode the 2
TextBoxes are set back to their default mode with the current header
information inside the TextBoxes, the 2 TextBoxCounters would return to a
visible state and the HeaderDirectionsLabel would show another set of
directions for editMode.

This is why I need to know exactly how to handle this sort of stuff with
accessing controls from outside the page itself. Am I going to far by saying
that I need to have it done this way? I am looking at the plans for the 7
wizard steps, and it looks like putting all of that code inside the page
class would make the page very huge and bulky for what it does. It is
looking like the full 7 step wizard will take up around 300 or more code if
all in the page class. How should I continue with the controls access issue?
"Joy" <Jo*@discussions.microsoft.comwrote in message
news:06**********************************@microsof t.com...
Hi Andy,
I would have been better equipped to help you, had i been aware of your
business scenario.

However, if you have more than 3 control's value to be passed as parameter
then i would suggest you to create a Parameter class. The following
example
will make the suggestion more clear for you:

Suppose you had to design an Customer registration page.
Suppose it had the following text fields:
1. Name
2. Age
3. City
4. Country
5. Language
6. Phone
7. Fax

You can write a Customer class that has the following private members and
should also be supported by getter/setter properties for each of the
private
members:

Public Class Customer
{
Private string strName ;
Private string strAge;
Private string strCity;
Private string strCountry;
Private string strLanguage;
Private string strPhone;
Private string strFax;

//Getter/Setter properties will follow here
public string Name
{
get
{
return strName ;
}
set
{
strName = value;
}
}

}

Then write the Data layer methods as such that they accept Customer class
object as parameters.
In the UI layer first make a Customer object and then initialise all its
properties with control's values and then make an object of the data layer
and call the DB method on this object thereby passing it the Customer
object
as parameter.

Please let me know if this worked for you.

regards,
Joy

"Andy B" wrote:
>I would have at least 8 or so UI controls that the class would need to
have
access to. Is this an unusual amount of parameters? I was possibly
thinking
of sending a collection of controls but not for sure if that will work or
not...
"Joy" <Jo*@discussions.microsoft.comwrote in message
news:A3**********************************@microso ft.com...
Hi Andy,
It is not a good practice to add some UI code in your data layer.
Normally
we write the Data Access layer to abstract the database related code
from
business and Presentation layer code.

Instead i would suggest you to write parameterized methods in your data
layer and make an object of this class in business/UI layer and then
call
these methods from there.

for example you can have a method that authenticates user so you can do
it
this way:

In data layer:

Public function AuthenticateUser(ByVal userName as string, ByVal
password
as
string) As boolean

'Make the Db call here and then return the result as true/false
depending
on
whether you got a row for the given username-password or not.

End function

Please let me know if it worked for you.else send me the code that you
are
writing.

regards,
Joy

"Andy B" wrote:

I have a class I am creating for data access. I need to access
controls
from
inside the class that are on a particular page. How do I do this? or
is
creating an instance of the page class and using FindControl the only
way
to
do it?




Jun 27 '08 #5
Hi Andy,
After going thru the task that you have in hand i would still suggest the
same way as i had told you earlier because of the following reasons:
1. Non Bulky code for UI - If you decide to make use of parametrized class,
then you can be rest assured that it is not going to make your UI page bulky,
the reason is even if you write the code in data access layer then also that
DLL will be loaded in the context of Page DLL, in essence lines of code
written in the data access class is not going to reduce the actual code being
loaded in runtime.
2. Runtime - As a general practice we should choose to do most of the things
statically rather than at runtime. For exampls, if you choose to write the
code in Data access layer then to be able to grab the UI controls of the page
you would first need the Http Context (executing context) and then only you
would be able to access the controls.

ALTERNATIVE Approach:
In .NET 2.0 we have a new feature called Cross-page posting, in this you can
have a UI page posting itself to a different page and in the code behind of
that page you can easily access the previous page's controls. The reason you
are able to do so is in this the UI page (having the controls) is a strongly
typed class and the next page can easily access this class.

Take a look at the following URL for cross-page posting example:

http://blogs.msdn.com/tinghaoy/archi...15/504357.aspx

regards,
Joy

"Andy B" wrote:
Hi Joy,

Sorry it took so long to get back to you on this subject. I haven't tried
your idea yet, but it is an interesting idea for some other part of the
project possibly. I don't think this will work directly for this particular
problem. Here is in some more detail of what I need to do, now that I have
clearance to do so. On this particular page, there is a wizard control that
has 7 different steps to it. In step 1, there are the following controls:
1. ContractHeaderDirectionsLabel - Gives directions for step 1 of the
wizard.
2. ContractTitleTextBox - A textbox that will contain a title for the
created contract (entered by user).
3. ContractTitleTextBoxCounter - A custom built control that counts the
words/characters in the ContractTitleTextBox.
4. ContractTypeTextBox - A textbox that will contain the type of contract
being created (entered by user).
5. ContractTypeTextBoxCounter - A custom built control that counts the
words/characters in the ContractTypeTextBox.
6. HeaderActionButton - A LinkButton that when pressed, either initially
saves or saves changes in the contract header depending on the state of the
wizardStep.

The different "states" of the wizard step are:
1. Default- shows the wizard in a state where the contract header has never
been created before. The HeaderActionButton above would have a Text value of
"Save header" and a CommandName value of "FirstSave".
2. Preview mode where the HeaderActionButton above has the TextValue of
"Edit header" and a CommandName of "EditHeader". In this mode, the 2
textboxes above (ContractType and ContractTitle) would be changed to
readonly, the 2 TextBoxCounters would be made to be invisible and the
ContractHeaderDirectionsLabel would be changed to display a new set of
directions.
3. EditMode - This mode would have the HeaderActionButton Text value set to
"Save changes" and the CommandName set to "SaveChanges". In this mode the 2
TextBoxes are set back to their default mode with the current header
information inside the TextBoxes, the 2 TextBoxCounters would return to a
visible state and the HeaderDirectionsLabel would show another set of
directions for editMode.

This is why I need to know exactly how to handle this sort of stuff with
accessing controls from outside the page itself. Am I going to far by saying
that I need to have it done this way? I am looking at the plans for the 7
wizard steps, and it looks like putting all of that code inside the page
class would make the page very huge and bulky for what it does. It is
looking like the full 7 step wizard will take up around 300 or more code if
all in the page class. How should I continue with the controls access issue?
"Joy" <Jo*@discussions.microsoft.comwrote in message
news:06**********************************@microsof t.com...
Hi Andy,
I would have been better equipped to help you, had i been aware of your
business scenario.

However, if you have more than 3 control's value to be passed as parameter
then i would suggest you to create a Parameter class. The following
example
will make the suggestion more clear for you:

Suppose you had to design an Customer registration page.
Suppose it had the following text fields:
1. Name
2. Age
3. City
4. Country
5. Language
6. Phone
7. Fax

You can write a Customer class that has the following private members and
should also be supported by getter/setter properties for each of the
private
members:

Public Class Customer
{
Private string strName ;
Private string strAge;
Private string strCity;
Private string strCountry;
Private string strLanguage;
Private string strPhone;
Private string strFax;

//Getter/Setter properties will follow here
public string Name
{
get
{
return strName ;
}
set
{
strName = value;
}
}

}

Then write the Data layer methods as such that they accept Customer class
object as parameters.
In the UI layer first make a Customer object and then initialise all its
properties with control's values and then make an object of the data layer
and call the DB method on this object thereby passing it the Customer
object
as parameter.

Please let me know if this worked for you.

regards,
Joy

"Andy B" wrote:
I would have at least 8 or so UI controls that the class would need to
have
access to. Is this an unusual amount of parameters? I was possibly
thinking
of sending a collection of controls but not for sure if that will work or
not...
"Joy" <Jo*@discussions.microsoft.comwrote in message
news:A3**********************************@microsof t.com...
Hi Andy,
It is not a good practice to add some UI code in your data layer.
Normally
we write the Data Access layer to abstract the database related code
from
business and Presentation layer code.

Instead i would suggest you to write parameterized methods in your data
layer and make an object of this class in business/UI layer and then
call
these methods from there.

for example you can have a method that authenticates user so you can do
it
this way:

In data layer:

Public function AuthenticateUser(ByVal userName as string, ByVal
password
as
string) As boolean

'Make the Db call here and then return the result as true/false
depending
on
whether you got a row for the given username-password or not.

End function

Please let me know if it worked for you.else send me the code that you
are
writing.

regards,
Joy

"Andy B" wrote:

I have a class I am creating for data access. I need to access
controls
from
inside the class that are on a particular page. How do I do this? or
is
creating an instance of the page class and using FindControl the only
way
to
do it?




Jun 27 '08 #6
So I create a class that holds the values required to switch the UI to the
different states, pass the controls to this class in the UI and then change
the values elsewhere? If I had an example of doing your idea with an actual
control (like a textbox) then It would be easier to get how to do...
"Joy" <Jo*@discussions.microsoft.comwrote in message
news:A9**********************************@microsof t.com...
Hi Andy,
After going thru the task that you have in hand i would still suggest the
same way as i had told you earlier because of the following reasons:
1. Non Bulky code for UI - If you decide to make use of parametrized
class,
then you can be rest assured that it is not going to make your UI page
bulky,
the reason is even if you write the code in data access layer then also
that
DLL will be loaded in the context of Page DLL, in essence lines of code
written in the data access class is not going to reduce the actual code
being
loaded in runtime.
2. Runtime - As a general practice we should choose to do most of the
things
statically rather than at runtime. For exampls, if you choose to write the
code in Data access layer then to be able to grab the UI controls of the
page
you would first need the Http Context (executing context) and then only
you
would be able to access the controls.

ALTERNATIVE Approach:
In .NET 2.0 we have a new feature called Cross-page posting, in this you
can
have a UI page posting itself to a different page and in the code behind
of
that page you can easily access the previous page's controls. The reason
you
are able to do so is in this the UI page (having the controls) is a
strongly
typed class and the next page can easily access this class.

Take a look at the following URL for cross-page posting example:

http://blogs.msdn.com/tinghaoy/archi...15/504357.aspx

regards,
Joy

"Andy B" wrote:
>Hi Joy,

Sorry it took so long to get back to you on this subject. I haven't tried
your idea yet, but it is an interesting idea for some other part of the
project possibly. I don't think this will work directly for this
particular
problem. Here is in some more detail of what I need to do, now that I
have
clearance to do so. On this particular page, there is a wizard control
that
has 7 different steps to it. In step 1, there are the following controls:
1. ContractHeaderDirectionsLabel - Gives directions for step 1 of the
wizard.
2. ContractTitleTextBox - A textbox that will contain a title for the
created contract (entered by user).
3. ContractTitleTextBoxCounter - A custom built control that counts the
words/characters in the ContractTitleTextBox.
4. ContractTypeTextBox - A textbox that will contain the type of contract
being created (entered by user).
5. ContractTypeTextBoxCounter - A custom built control that counts the
words/characters in the ContractTypeTextBox.
6. HeaderActionButton - A LinkButton that when pressed, either initially
saves or saves changes in the contract header depending on the state of
the
wizardStep.

The different "states" of the wizard step are:
1. Default- shows the wizard in a state where the contract header has
never
been created before. The HeaderActionButton above would have a Text value
of
"Save header" and a CommandName value of "FirstSave".
2. Preview mode where the HeaderActionButton above has the TextValue of
"Edit header" and a CommandName of "EditHeader". In this mode, the 2
textboxes above (ContractType and ContractTitle) would be changed to
readonly, the 2 TextBoxCounters would be made to be invisible and the
ContractHeaderDirectionsLabel would be changed to display a new set of
directions.
3. EditMode - This mode would have the HeaderActionButton Text value set
to
"Save changes" and the CommandName set to "SaveChanges". In this mode the
2
TextBoxes are set back to their default mode with the current header
information inside the TextBoxes, the 2 TextBoxCounters would return to a
visible state and the HeaderDirectionsLabel would show another set of
directions for editMode.

This is why I need to know exactly how to handle this sort of stuff with
accessing controls from outside the page itself. Am I going to far by
saying
that I need to have it done this way? I am looking at the plans for the 7
wizard steps, and it looks like putting all of that code inside the page
class would make the page very huge and bulky for what it does. It is
looking like the full 7 step wizard will take up around 300 or more code
if
all in the page class. How should I continue with the controls access
issue?
"Joy" <Jo*@discussions.microsoft.comwrote in message
news:06**********************************@microso ft.com...
Hi Andy,
I would have been better equipped to help you, had i been aware of your
business scenario.

However, if you have more than 3 control's value to be passed as
parameter
then i would suggest you to create a Parameter class. The following
example
will make the suggestion more clear for you:

Suppose you had to design an Customer registration page.
Suppose it had the following text fields:
1. Name
2. Age
3. City
4. Country
5. Language
6. Phone
7. Fax

You can write a Customer class that has the following private members
and
should also be supported by getter/setter properties for each of the
private
members:

Public Class Customer
{
Private string strName ;
Private string strAge;
Private string strCity;
Private string strCountry;
Private string strLanguage;
Private string strPhone;
Private string strFax;

//Getter/Setter properties will follow here
public string Name
{
get
{
return strName ;
}
set
{
strName = value;
}
}

}

Then write the Data layer methods as such that they accept Customer
class
object as parameters.
In the UI layer first make a Customer object and then initialise all
its
properties with control's values and then make an object of the data
layer
and call the DB method on this object thereby passing it the Customer
object
as parameter.

Please let me know if this worked for you.

regards,
Joy

"Andy B" wrote:

I would have at least 8 or so UI controls that the class would need to
have
access to. Is this an unusual amount of parameters? I was possibly
thinking
of sending a collection of controls but not for sure if that will work
or
not...
"Joy" <Jo*@discussions.microsoft.comwrote in message
news:A3**********************************@microso ft.com...
Hi Andy,
It is not a good practice to add some UI code in your data layer.
Normally
we write the Data Access layer to abstract the database related code
from
business and Presentation layer code.

Instead i would suggest you to write parameterized methods in your
data
layer and make an object of this class in business/UI layer and then
call
these methods from there.

for example you can have a method that authenticates user so you can
do
it
this way:

In data layer:

Public function AuthenticateUser(ByVal userName as string, ByVal
password
as
string) As boolean

'Make the Db call here and then return the result as true/false
depending
on
whether you got a row for the given username-password or not.

End function

Please let me know if it worked for you.else send me the code that
you
are
writing.

regards,
Joy

"Andy B" wrote:

I have a class I am creating for data access. I need to access
controls
from
inside the class that are on a particular page. How do I do this?
or
is
creating an instance of the page class and using FindControl the
only
way
to
do it?





Jun 27 '08 #7
Hi Andy,
Did you take a look at how to make use of Cross-page posting?

give me your mail ID and i will mail you the sample code for parmaterized
class and would you want it in VB .NET or C#?

regards,
Joy

"Andy B" wrote:
So I create a class that holds the values required to switch the UI to the
different states, pass the controls to this class in the UI and then change
the values elsewhere? If I had an example of doing your idea with an actual
control (like a textbox) then It would be easier to get how to do...
"Joy" <Jo*@discussions.microsoft.comwrote in message
news:A9**********************************@microsof t.com...
Hi Andy,
After going thru the task that you have in hand i would still suggest the
same way as i had told you earlier because of the following reasons:
1. Non Bulky code for UI - If you decide to make use of parametrized
class,
then you can be rest assured that it is not going to make your UI page
bulky,
the reason is even if you write the code in data access layer then also
that
DLL will be loaded in the context of Page DLL, in essence lines of code
written in the data access class is not going to reduce the actual code
being
loaded in runtime.
2. Runtime - As a general practice we should choose to do most of the
things
statically rather than at runtime. For exampls, if you choose to write the
code in Data access layer then to be able to grab the UI controls of the
page
you would first need the Http Context (executing context) and then only
you
would be able to access the controls.

ALTERNATIVE Approach:
In .NET 2.0 we have a new feature called Cross-page posting, in this you
can
have a UI page posting itself to a different page and in the code behind
of
that page you can easily access the previous page's controls. The reason
you
are able to do so is in this the UI page (having the controls) is a
strongly
typed class and the next page can easily access this class.

Take a look at the following URL for cross-page posting example:

http://blogs.msdn.com/tinghaoy/archi...15/504357.aspx

regards,
Joy

"Andy B" wrote:
Hi Joy,

Sorry it took so long to get back to you on this subject. I haven't tried
your idea yet, but it is an interesting idea for some other part of the
project possibly. I don't think this will work directly for this
particular
problem. Here is in some more detail of what I need to do, now that I
have
clearance to do so. On this particular page, there is a wizard control
that
has 7 different steps to it. In step 1, there are the following controls:
1. ContractHeaderDirectionsLabel - Gives directions for step 1 of the
wizard.
2. ContractTitleTextBox - A textbox that will contain a title for the
created contract (entered by user).
3. ContractTitleTextBoxCounter - A custom built control that counts the
words/characters in the ContractTitleTextBox.
4. ContractTypeTextBox - A textbox that will contain the type of contract
being created (entered by user).
5. ContractTypeTextBoxCounter - A custom built control that counts the
words/characters in the ContractTypeTextBox.
6. HeaderActionButton - A LinkButton that when pressed, either initially
saves or saves changes in the contract header depending on the state of
the
wizardStep.

The different "states" of the wizard step are:
1. Default- shows the wizard in a state where the contract header has
never
been created before. The HeaderActionButton above would have a Text value
of
"Save header" and a CommandName value of "FirstSave".
2. Preview mode where the HeaderActionButton above has the TextValue of
"Edit header" and a CommandName of "EditHeader". In this mode, the 2
textboxes above (ContractType and ContractTitle) would be changed to
readonly, the 2 TextBoxCounters would be made to be invisible and the
ContractHeaderDirectionsLabel would be changed to display a new set of
directions.
3. EditMode - This mode would have the HeaderActionButton Text value set
to
"Save changes" and the CommandName set to "SaveChanges". In this mode the
2
TextBoxes are set back to their default mode with the current header
information inside the TextBoxes, the 2 TextBoxCounters would return to a
visible state and the HeaderDirectionsLabel would show another set of
directions for editMode.

This is why I need to know exactly how to handle this sort of stuff with
accessing controls from outside the page itself. Am I going to far by
saying
that I need to have it done this way? I am looking at the plans for the 7
wizard steps, and it looks like putting all of that code inside the page
class would make the page very huge and bulky for what it does. It is
looking like the full 7 step wizard will take up around 300 or more code
if
all in the page class. How should I continue with the controls access
issue?
"Joy" <Jo*@discussions.microsoft.comwrote in message
news:06**********************************@microsof t.com...
Hi Andy,
I would have been better equipped to help you, had i been aware of your
business scenario.

However, if you have more than 3 control's value to be passed as
parameter
then i would suggest you to create a Parameter class. The following
example
will make the suggestion more clear for you:

Suppose you had to design an Customer registration page.
Suppose it had the following text fields:
1. Name
2. Age
3. City
4. Country
5. Language
6. Phone
7. Fax

You can write a Customer class that has the following private members
and
should also be supported by getter/setter properties for each of the
private
members:

Public Class Customer
{
Private string strName ;
Private string strAge;
Private string strCity;
Private string strCountry;
Private string strLanguage;
Private string strPhone;
Private string strFax;

//Getter/Setter properties will follow here
public string Name
{
get
{
return strName ;
}
set
{
strName = value;
}
}

}

Then write the Data layer methods as such that they accept Customer
class
object as parameters.
In the UI layer first make a Customer object and then initialise all
its
properties with control's values and then make an object of the data
layer
and call the DB method on this object thereby passing it the Customer
object
as parameter.

Please let me know if this worked for you.

regards,
Joy

"Andy B" wrote:

I would have at least 8 or so UI controls that the class would need to
have
access to. Is this an unusual amount of parameters? I was possibly
thinking
of sending a collection of controls but not for sure if that will work
or
not...
"Joy" <Jo*@discussions.microsoft.comwrote in message
news:A3**********************************@microsof t.com...
Hi Andy,
It is not a good practice to add some UI code in your data layer.
Normally
we write the Data Access layer to abstract the database related code
from
business and Presentation layer code.

Instead i would suggest you to write parameterized methods in your
data
layer and make an object of this class in business/UI layer and then
call
these methods from there.

for example you can have a method that authenticates user so you can
do
it
this way:

In data layer:

Public function AuthenticateUser(ByVal userName as string, ByVal
password
as
string) As boolean

'Make the Db call here and then return the result as true/false
depending
on
whether you got a row for the given username-password or not.

End function

Please let me know if it worked for you.else send me the code that
you
are
writing.

regards,
Joy

"Andy B" wrote:

I have a class I am creating for data access. I need to access
controls
from
inside the class that are on a particular page. How do I do this?
or
is
creating an instance of the page class and using FindControl the
only
way
to
do it?





Jun 27 '08 #8

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
by: Peter Frost | last post by:
Please help I don't know if this is possible but what I would really like to do is to use On Error Goto to capture the code that is being executed when an error occurs. Any help would be much...
6
by: grist2mill | last post by:
I want to create a standard tool bar that appears on all pages that is a control. The toolbar has a button 'New'. What I wolud like when the user clicks on 'New' depends on the page they are on. I...
10
by: Davíð Þórisson | last post by:
Please can someone tell me how on earth to create an instance of my top level (base) Page class so that I can access it's objects from an user control?? Someone told me public myParent =...
6
by: Davids | last post by:
having a 100% working aspx page I wanted to create a user control from a small DataList section (which has an ID="DataList1") of the page, so I created an ascx file with the DataList and Register...
8
by: Ravi Ambros Wallau | last post by:
Hey guys: What can I do when an "Error Creating Control" is displayed on the form (instead of the control), and a tooltip indicating the error never is displayed? Is there some log, some hidden...
3
by: Mr Newbie | last post by:
I am messing around with Web User Controls at present and (think) I have discovered the following. 1.) The identifier for the control in the code behind must match the ID for the control on the...
1
by: Brad | last post by:
Thanks for taking the time to read my question. I have a table of data that has Date, Data and Category. I need to show, in a report, each Categories Data by Date. The Date has to be it's own...
37
by: Joergen Bech | last post by:
(Slightly religious question): Suppose I have the following class: ---snip--- Public Class MyClass Private _MyVariable As Integer Public Property MyVariable() As Integer Get
5
by: John Kotuby | last post by:
Hi all, This is my first time trying to creaet and use a custome Web Control in a Web Site project in ASP.NET 2.0 with VS 2005 and VB. I created the control in a separate Web Control Library...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.