[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?
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.
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.
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);
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.
Re: how to pass a page to a class?
I like it. I can run with that. Thanks
Re: [RESOLVED] how to pass a page to a class?
Post back if you have more questions or frustrations with this :D
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.
Re: [RESOLVED] how to pass a page to a class?
Quote:
Originally Posted by
MarkT
I assume I will. I'm finally moving from VB6 to C#. The syntax it a little different.
little different? :rolleyes:
Re: [RESOLVED] how to pass a page to a class?
Quote:
Originally Posted by
Pradeep1210
little different? :rolleyes:
Hee hee.
Just a little different, but stick with it, you will get there.
Gary
Re: [RESOLVED] how to pass a page to a class?
Quote:
Originally Posted by
Pradeep1210
little different? :rolleyes:
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#.
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