Results 1 to 12 of 12

Thread: [RESOLVED] how to pass a page to a class?

  1. #1

    Thread Starter
    PowerPoster
    Join Date
    Jun 2001
    Location
    Trafalgar, IN
    Posts
    4,141

    Resolved [RESOLVED] how to pass a page to a class?

    Ok let’s see if I can explain this.

    What I would like to do is pass a page to a class so I can use Requst.Form to set values as I need them. Basically what I have is a number of page types that I need to set according to this value. For example

    Code:
    Switch (PageType) 
    {
    	case “easy”:
    		strValue1 = Request.Form(“firstvalue”);
    		strValue2 = Request.Form(“secondvalue”);
                    strValue2 = Request.Form(“thirdvalue”);
                    break;
    	case “medium”
    		strValue1 = Request.Form(“thirdvalue”);
    		strValue2 = Request.Form(“firstvalue”);
                    strValue2 = Request.Form(“secondvalue”);
                    break;
    	case “medium”
    		strValue1 = Request.Form(“thirdvalue”);
    		strValue2 = Request.Form(“secondvalue”);
                    strValue2 = Request.Form(“firstvalue”);
                    break;
    }
    I realize the syntax isn’t correct here but I hope this gives you an idea of what I’m trying to do. I tried to simplify what I’m trying to do to explain it. In reality the page being passed in could have a couple dozen form variables that need to be checked.

    Any ideas or a better way of handling it?

  2. #2
    VB Addict Pradeep1210's Avatar
    Join Date
    Apr 2004
    Location
    Inside the CPU...
    Posts
    6,614

    Re: how to pass a page to a class?

    Use Server.Transfer to move to new page. This way the old page along with all its values is still accessible to you in the new page.
    Pradeep, Microsoft MVP (Visual Basic)
    Please appreciate posts that have helped you by clicking icon on the left of the post.
    "A problem well stated is a problem half solved." — Charles F. Kettering

    Read articles on My Blog101 LINQ SamplesJSON ValidatorXML Schema Validator"How Do I" videos on MSDNVB.NET and C# ComparisonGood Coding PracticesVBForums Reputation SaverString EnumSuper Simple Tetris Game


    (2010-2013)
    NB: I do not answer coding questions via PM. If you want my help, then make a post and PM me it's link. If I can help, trust me I will...

  3. #3

    Thread Starter
    PowerPoster
    Join Date
    Jun 2001
    Location
    Trafalgar, IN
    Posts
    4,141

    Re: how to pass a page to a class?

    Unfortunately that won’t work in my case. I guess a more detailed description is need. What I’m working on is an app that does dynamic charting. There are a number of different types of charts, all of which require some common attributes (title, height, width etc.) and a number of unique attributes. For example let’s assume you have a line graph. ChartType = LineGraph and as the measure (intMeasure) you might be plotting is the y-axis value. In the next call I might have ChartType = PieGraph and intMeasure this time would be the percent the pie slice uses. So depending on ChartType you would either have

    intMeasure = Request.Form(“yaxis”)
    or
    intMeasure = Request.Form(“percent”)

    Basically I want is to have a generic page that generates the charts. When you call the page, it passes a number of form variables to that page. From there it calls a class that crunches the numbers and passes the data back to the form to show the chart.

    Since the values used to generate the chart will be populated from different form variables based on the chart type, what I’m really looking to do is pass all the form variables to the class in one lump, use the ones I need and send back the results based on the ChartType. One chart may use a couple dozen variables and the next may only use a handful and the mapping of the variables will be different.

    Up to this point we have been one offing a page, changing a variable here and there and using it to generate a new chart. Needless to say it has become a nightmare to maintain. Since the App is being upgraded from Classic ASP to .NET it seems to be a good time to clean it up. If there is a way to pass a page to the class so I can access the form variable I should able to create that single generic page to present the charts.

    I’m pretty new to this .NET stuff so I’m not even sure if I’m heading down the right road.

  4. #4
    I'm about to be a PowerPoster! mendhak's Avatar
    Join Date
    Feb 2002
    Location
    Ulaan Baator GooGoo: Frog
    Posts
    38,170

    Re: how to pass a page to a class?

    Instead of passing a page, pass a class.

    Start by defining a class structure that represents everything about the graph that your graphic class covers. So for example you could have

    Code:
    public class GraphingInfo
    {
    public string Graphname { get; set;}
    public int YAxis { get; set;}
    public int Percent {get; set;}
    public bool PacmanShape {get; set;}
    }
    The idea is that you generate your class with everything in it. When the originating page tries to call the graphing class, it should first take all of the request form variables itself, declare a new GraphingInfo object, populate its properties.

    Code:
    GraphingInfo gi = new GraphingInfo();
    gi.Graphname = Request.Form["gname"];
    gi.YAxis = 92;
    gi.PacmanShape = true;

    So in this case you're not populating all of the properties. But once you have the gi object, you can call your graphing class' constructor or method.

    Code:
    GraphingClass gc = new GraphingClass();
    gc.CreateGraphOrWhateverYourMethodIsCalled(gi);

  5. #5
    I'm about to be a PowerPoster! mendhak's Avatar
    Join Date
    Feb 2002
    Location
    Ulaan Baator GooGoo: Frog
    Posts
    38,170

    Re: how to pass a page to a class?

    Right so in your actual GraphingClass, you look at the properties of the gi object instead of the Request.Form. Also note that I didn't populate Percent - not all properties have to be populated.

  6. #6

    Thread Starter
    PowerPoster
    Join Date
    Jun 2001
    Location
    Trafalgar, IN
    Posts
    4,141

    Re: how to pass a page to a class?

    I like it. I can run with that. Thanks

  7. #7
    I'm about to be a PowerPoster! mendhak's Avatar
    Join Date
    Feb 2002
    Location
    Ulaan Baator GooGoo: Frog
    Posts
    38,170

    Re: [RESOLVED] how to pass a page to a class?

    Post back if you have more questions or frustrations with this

  8. #8

    Thread Starter
    PowerPoster
    Join Date
    Jun 2001
    Location
    Trafalgar, IN
    Posts
    4,141

    Re: [RESOLVED] how to pass a page to a class?

    I assume I will. I'm finally moving from VB6 to C#. The syntax it a little different.

  9. #9
    VB Addict Pradeep1210's Avatar
    Join Date
    Apr 2004
    Location
    Inside the CPU...
    Posts
    6,614

    Re: [RESOLVED] how to pass a page to a class?

    Quote Originally Posted by MarkT View Post
    I assume I will. I'm finally moving from VB6 to C#. The syntax it a little different.
    little different?
    Pradeep, Microsoft MVP (Visual Basic)
    Please appreciate posts that have helped you by clicking icon on the left of the post.
    "A problem well stated is a problem half solved." — Charles F. Kettering

    Read articles on My Blog101 LINQ SamplesJSON ValidatorXML Schema Validator"How Do I" videos on MSDNVB.NET and C# ComparisonGood Coding PracticesVBForums Reputation SaverString EnumSuper Simple Tetris Game


    (2010-2013)
    NB: I do not answer coding questions via PM. If you want my help, then make a post and PM me it's link. If I can help, trust me I will...

  10. #10
    PowerPoster gep13's Avatar
    Join Date
    Nov 2004
    Location
    The Granite City
    Posts
    21,963

    Re: [RESOLVED] how to pass a page to a class?

    Quote Originally Posted by Pradeep1210 View Post
    little different?
    Hee hee.

    Just a little different, but stick with it, you will get there.

    Gary

  11. #11

    Thread Starter
    PowerPoster
    Join Date
    Jun 2001
    Location
    Trafalgar, IN
    Posts
    4,141

    Re: [RESOLVED] how to pass a page to a class?

    Quote Originally Posted by Pradeep1210 View Post
    little different?
    Oh yea!

    Actually, I kind of like it. I have gotten past the point where I have to google every error I get to figure out what it means. And for that matter, I'm getting fewer and fewer errors. My biggest problem now is I'm still coding like I'm using VB and not levering the full powers of C#.

  12. #12
    PowerPoster gep13's Avatar
    Join Date
    Nov 2004
    Location
    The Granite City
    Posts
    21,963

    Re: [RESOLVED] how to pass a page to a class?

    Well, don't be scared to ask questions in these forums, there will always be someone who will be able to guide you.

    Gary

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