CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 12 of 12
  1. #1
    Join Date
    Jan 2008
    Posts
    43

    Angry how to read TextBox1.Text from helperFunctions.cs

    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.

  2. #2
    Join Date
    Mar 2002
    Location
    St. Petersburg, Florida, USA
    Posts
    12,125

    Re: how to read TextBox1.Text from helperFunctions.cs

    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.
    TheCPUWizard is a registered trademark, all rights reserved. (If this post was helpful, please RATE it!)
    2008, 2009,2010
    In theory, there is no difference between theory and practice; in practice there is.

    * Join the fight, refuse to respond to posts that contain code outside of [code] ... [/code] tags. See here for instructions
    * How NOT to post a question here
    * Of course you read this carefully before you posted
    * Need homework help? Read this first

  3. #3
    Join Date
    Jan 2008
    Posts
    43

    Re: how to read TextBox1.Text from helperFunctions.cs

    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"));

    }

  4. #4
    Join Date
    Mar 2002
    Location
    St. Petersburg, Florida, USA
    Posts
    12,125

    Re: how to read TextBox1.Text from helperFunctions.cs

    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.
    TheCPUWizard is a registered trademark, all rights reserved. (If this post was helpful, please RATE it!)
    2008, 2009,2010
    In theory, there is no difference between theory and practice; in practice there is.

    * Join the fight, refuse to respond to posts that contain code outside of [code] ... [/code] tags. See here for instructions
    * How NOT to post a question here
    * Of course you read this carefully before you posted
    * Need homework help? Read this first

  5. #5
    Join Date
    Jan 2008
    Posts
    43

    Re: how to read TextBox1.Text from helperFunctions.cs

    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.

  6. #6
    Join Date
    Jan 2008
    Posts
    43

    Re: how to read TextBox1.Text from helperFunctions.cs

    I mean textboxes, not checkboxes, sorry

  7. #7
    Join Date
    Mar 2002
    Location
    St. Petersburg, Florida, USA
    Posts
    12,125

    Re: how to read TextBox1.Text from helperFunctions.cs

    Quote Originally Posted by bulbish View Post
    ... 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.
    TheCPUWizard is a registered trademark, all rights reserved. (If this post was helpful, please RATE it!)
    2008, 2009,2010
    In theory, there is no difference between theory and practice; in practice there is.

    * Join the fight, refuse to respond to posts that contain code outside of [code] ... [/code] tags. See here for instructions
    * How NOT to post a question here
    * Of course you read this carefully before you posted
    * Need homework help? Read this first

  8. #8
    Join Date
    Jan 2008
    Posts
    43

    Re: how to read TextBox1.Text from helperFunctions.cs

    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.

  9. #9
    Join Date
    Mar 2002
    Location
    St. Petersburg, Florida, USA
    Posts
    12,125

    Re: how to read TextBox1.Text from helperFunctions.cs

    Quote Originally Posted by bulbish View Post
    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.
    TheCPUWizard is a registered trademark, all rights reserved. (If this post was helpful, please RATE it!)
    2008, 2009,2010
    In theory, there is no difference between theory and practice; in practice there is.

    * Join the fight, refuse to respond to posts that contain code outside of [code] ... [/code] tags. See here for instructions
    * How NOT to post a question here
    * Of course you read this carefully before you posted
    * Need homework help? Read this first

  10. #10
    Join Date
    Jan 2008
    Posts
    43

    Re: how to read TextBox1.Text from helperFunctions.cs

    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.

  11. #11
    Join Date
    Mar 2002
    Location
    St. Petersburg, Florida, USA
    Posts
    12,125

    Re: how to read TextBox1.Text from helperFunctions.cs

    Quote Originally Posted by bulbish View Post
    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.....
    TheCPUWizard is a registered trademark, all rights reserved. (If this post was helpful, please RATE it!)
    2008, 2009,2010
    In theory, there is no difference between theory and practice; in practice there is.

    * Join the fight, refuse to respond to posts that contain code outside of [code] ... [/code] tags. See here for instructions
    * How NOT to post a question here
    * Of course you read this carefully before you posted
    * Need homework help? Read this first

  12. #12
    Join Date
    Oct 2006
    Posts
    181

    Re: how to read TextBox1.Text from helperFunctions.cs

    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.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured