Calling Codebehind Function

Aspnot

Freshman
Joined
Feb 24, 2004
Messages
37
I have been an ASP developer for years and am trying to get my arms around ASP.NET. I am trying to call a function from my ASPX file that exists in my VB file. The function makes a call to SQL Server to get a list of records to display. I am trying to do all of the looping in the VB file and just have that information returned to the ASPX file with a Response.Write.

I have seen somewhere where the person created the DataReader in the ASPX file and then referenced it from the VB file. This allowed him to loop through the resultset in the ASPX file. I would prefer to do my looping in the ASPX file and return a StringBuilder or a Response.Write or even an HTMLTextWriter.

I have also seen where I can create a namespace and do it that way. Again, this just feels too clunky. Maybe this is the best way to do it, but I really don't know.

What do you folks do? I would like to see a couple of different suggestions so that I can debate the pros and cons.

Thanks in advance!!
 
Sending all of the HTML to the browser with something like Response.Write has gone the way of the dodo bird. The whole point of ASP.NET is to be able to put controls (stock or custom) on the web form and then access them programmatically. ASP.NET handles the rest (translating code into HTML).

I was probably in the same boat as you are right now. When I first became familiar with ASP.NET, I felt that I was losing some flexibility by relying on this method. Once you get used to this approach though, you will find your overall production increases dramatically.

You should be able to find many examples around the site and on MSDN.
 
The layout I want is something like

Headline Title (a few spaces) Date

Text of the abstract goes here. Blah Blah Blah


There may be up to 5 headlines at any given time. How would I preload the ASP.NET form to be able to handle this? Can I just use a container control and then populate it with the necessary controls at runtime?

Just trying to get a grip on this.

Thanks!!
 
You could create the controls yourself within a container control, or alternatively have a look at tthe DataGrid, DataList or DataRepeater controls - these can take a lot of the effort out of building data driven web pages.
 
Back
Top