Objected oriented programming (ASP.NET C#)

Soldato
Joined
12 Jan 2004
Posts
6,824
Location
Londinium
Hi guys,

its been a while since ive done OO programming so am a little rusty. I am building a web application that will take a dynamic (via javascript) number of input fields. These will then be submitted and processed but I am a bit unsure how to achieve this so I have a few questions:

1.) The user will be able to click a button that will add more input fields via javascript. Will these fields be accessable to c# once submitted, bearing in mind that they wont be <asp:... tags? Is it enough to add the 'runat="server"' property to the standard HTML input tag?

2.) Once the input fields have been submitted what is the best way to process them? I am thinking that i should design a class describing a group of inputs and for each group submitted, create an object of that class and populate it with the input values. How do you keep track of a variable number of objects created? Is the best way for each object, assign it to an array index and then simply loop through the array to access the object?

Any help would be great guys!
 
nero120 said:
1.) The user will be able to click a button that will add more input fields via javascript. Will these fields be accessable to c# once submitted, bearing in mind that they wont be <asp:... tags? Is it enough to add the 'runat="server"' property to the standard HTML input tag?

Its been a while since i did any asp.net but couldnt you declare the fields in the usual way (<asp:...) but set the visibility to false, then just switch it to true when the user clicks a button? Or is that not an option?

Matt
 
SoapSurgeon said:
Its been a while since i did any asp.net but couldnt you declare the fields in the usual way (<asp:...) but set the visibility to false, then just switch it to true when the user clicks a button? Or is that not an option?

Matt

As far as I know, the server renders the <asp:... tags into standard html (thats what the runat="server" property is for) and sends that to the client. Since javascript is client side, generating a <asp:... tag would not be properly interpreted by the client, so you'd have to use standard HTML tags. The only problem is, will the input values of the client-side generated fields be accessable to the c# code once submitted?
 
Remember that <asp:??? /> code is not HTML. It has to go through at least one additional process before i is given to the client.

as for you problem, personally I'd lose the ASP webcontrol all-together and do it the traditional way. Just code some javascript to add the input fields to your form upon the button press, and process the returned values as Request[???] values in Page_Load.

I've no doubt it could be done as a control (in fact you could wrap the method i've described into a usercontrol and make it generalised), but I'm a fan of the quick and dirty method :D

akakjs
 
akakjs said:
Remember that <asp:??? /> code is not HTML. It has to go through at least one additional process before i is given to the client.

as for you problem, personally I'd lose the ASP webcontrol all-together and do it the traditional way. Just code some javascript to add the input fields to your form upon the button press, and process the returned values as Request[???] values in Page_Load.

I've no doubt it could be done as a control (in fact you could wrap the method i've described into a usercontrol and make it generalised), but I'm a fan of the quick and dirty method :D

akakjs

Thanks dude, it does seem like the best way but cos I was doing it .net as opposed to classic, I had this feeling I should do it OO! Silly really, whatever works.

I just had another question for you, since I will not be using classes, I will need to write my c# functions in a seperate file and 'include' them in the main aspx file. All the examples Ive found are for including functions in classes and including the classes, which is what i dont want to do! So how can I write normak functions in seperate files and include them in the main aspx page?
 
What book would you recommend for learning ASP.NET 2.0?

Im an experienced programmer but never coded ASP or C# before, but I know php/css/xhtml/c/c++/java pretty well.

Thx
 
Back
Top Bottom