Click to See Complete Forum and Search --> : how to read TextBox1.Text from helperFunctions.cs


bulbish
November 8th, 2008, 02:35 PM
i need to read textbox1.text from one of my helper functions in a separate code file?

How do i do that?

I am passing the THIS pointer from the form to the helper function , but how do i get the text in the textbox? Please dont ask why, i'm not a newbie, it just has to be done this way, i cannot pass a string as an argument.

TheCPUWizard
November 8th, 2008, 02:42 PM
Modify the textbox to be public.

HOWEVER, I recomment STRONGLYagainst doing that.

If you can not pass the string, pass the TextBox itself.

In 7+ years of professionally developing ASP.NET soltuions, there has NEVER been a requirement to expose a control outside the enclosing class.

bulbish
November 8th, 2008, 02:49 PM
from the webform i'm doing:
dbc.insert(this, DonorID, formType);
And from the separate code file i'm doing:

public void insert(Control p,int userID, int formType)

{

TextBox tb = (TextBox)(p.FindControl("TextBoxTitle"));

}

TheCPUWizard
November 8th, 2008, 02:50 PM
That is simply BAD DESIGN. It increases coupling in ways that are not required, and even worse are not verifiable at compile time.

IF this approach was brought to me at a design review it would be rejected. If it was brought a second time, the person would be fired.

bulbish
November 8th, 2008, 02:59 PM
ok here is what i'm trying to do, maybe you can recommend a better way.

I have about 20 forms, each one of them has about 20 fields, out of which 10-15 fields are the same for all forms. I have a class that inserts filled out forms in the database, pretty much the same for all forms, except some minor adjustments. How do i pass all the checkboxes to the DB class from all 20 forms? The only other way i can think of is to copy and paste the DB code into all 20 pages, but this way if i need to change something later i would have to change it 20 times.

bulbish
November 8th, 2008, 03:01 PM
I mean textboxes, not checkboxes, sorry

TheCPUWizard
November 8th, 2008, 03:53 PM
... How do i pass all the checkboxes to the DB class from all 20 forms? ....

It does not matter if they are checkboxes, textboxes, labels, or any other UI element.

1) Your DB layer should know NOTHING about the UI. If you have a single reference to any of the UI namespaces in your DB code, you have serious problems.

2) The SAME is true about your UI layer, it should NOT have ANY references to System.Data

What you DO want is an interface that exposes a number of STRING properties.

Your UI class implements this interface and directs all of the information to the appropriate (protected) UI controls.

You pass the INTERFACE to your data layer for population.

bulbish
November 8th, 2008, 04:23 PM
ok i got your point, thats how i would normally do it myself. I was going to cheat a little this time but i think it was a bad idea. With this approach i'll have 30 lines of basically the same C# string field population code that i would have to copy and paste onto each one of my 20 forms. But if you say there is no better way then i guess this is the way to do it.

TheCPUWizard
November 8th, 2008, 04:32 PM
ok i got your point, thats how i would normally do it myself. I was going to cheat a little this time but i think it was a bad idea. With this approach i'll have 30 lines of basically the same C# string field population code that i would have to copy and paste onto each one of my 20 forms. But if you say there is no better way then i guess this is the way to do it.

There should not be that level of curring and pasting.....

WHY are your 20 forms (Apparently) totally independant if a large percentage of them contain common questions?

1) Create a custom control that represents 1 question
2) Create a custom control that represents a collection of questions
3) Modify your forms to all use this one common collection, populating as necessary
4) Implement the interface I described on your collection
5) Pass interface to DB (as mentioned previously.

Bingo, 20 different forms, with absolutely NO duplication of code.

bulbish
November 8th, 2008, 04:40 PM
i'll look into doing it as a custom control , that sounds like good advice.
Thanks for your help very much! I knew there had to be a way around this.

TheCPUWizard
November 8th, 2008, 04:45 PM
i'll look into doing it as a custom control , that sounds like good advice.
Thanks for your help very much! I knew there had to be a way around this.

Good Luck...Feel free to "ping" me if you run into a problem and I dont respond on thread.

In general I ONLY answer qquestions on thread, but sometimes things slip past me so a "tickle" can help.....

Scott.Macmaster
November 11th, 2008, 10:43 PM
Hmm, custom control to implement a db interface seems overly complicated. Plus it would lock you into the exact same set of controls and layout on each page unless your control had a number of properties to adjust layout. From your previous post it seems like you want to be able to vary the look. I'd start with a base class that implements your business logic. Have a property that represent each parameter. Make sure they are set to must override. Then have your web pages inherit from it. Override the properties from the base class to return the values of controls to the business logic functions.