Hello all,

I'm drawing a blank on how I should proceed with the final steps in completing my website. I guess to sum it up is I would essentially like to let the users be able to submit something that shows up on the home page and stays there (this being text that they've entered in a textbox).

I was originally going to do this through an arraylist in VB but my instructor said that it would be pretty nasty using an AL because I would have to code around the fact that I'm not going to know every specific ID that is being created since the controls would be created dynamically.

Then he mentioned just having them saved to a database and then running a stored procedure that would cycle through the saved items and have them displayed through a data view control.

What do you guys think would be the best, and simplest, way to make this happen?

Here is the run-down: I have 2 textboxes and a button. The first textbox is the title of what the user is writing and the other is the actual story. When the button is clicked I want it to take what was written in those 2 boxes and then make them appear in newly created labels (since it will be read only) and stay after post back.

I'm not asking for code as that would really defeat the purpose of me trying to learn how to do it and do it correctly but more or less just some suggestions on how to do it correctly.

Thanks guys!

Dani AI

Generated

Good instincts from and — persisting submissions and using a data-bound display is the cleanest, most maintainable route for multi-user, multi-visit content. Below is a compact, practical plan that fills gaps from the thread (why ArrayList/dynamic labels are awkward, how to handle security, moderation and basic performance) and gives minimal, concrete examples for a VB.NET + SQL Server stack.

A small, focused schema and a single insert path keep things simple and auditable. Example SQL + stored-proc and a VB.NET call:

-- table (SQL Server)
CREATE TABLE Posts (
  PostId INT IDENTITY(1,1) PRIMARY KEY,
  Title NVARCHAR(200) NOT NULL,
  Body NVARCHAR(MAX) NOT NULL,
  UserId INT NULL,
  CreatedAt DATETIME NOT NULL DEFAULT GETDATE(),
  ExpiresAt DATETIME NULL,
  IsApproved BIT NOT NULL DEFAULT 0
);

CREATE PROCEDURE dbo.InsertPost
  @Title NVARCHAR(200),
  @Body NVARCHAR(MAX),
  @UserId INT = NULL
AS
BEGIN
  INSERT INTO Posts (Title, Body, UserId) VALUES (@Title, @Body, @UserId);
  SELECT SCOPE_IDENTITY();
END
Using conn As New SqlConnection(connString)
  Using cmd As New SqlCommand("dbo.InsertPost", conn)
    cmd.CommandType = CommandType.StoredProcedure
    cmd.Parameters.AddWithValue("@Title", titleText)
    cmd.Parameters.AddWithValue("@Body", bodyText)
    cmd.Parameters.AddWithValue("@UserId", userId)
    conn.Open()
    Dim newId As Integer = Convert.ToInt32(cmd.ExecuteScalar())
  End Using
End Using

Render with a data-bound control (Repeater/ListView) rather than creating Labels dynamically — that avoids the viewstate/ID recreation pain worried about. Important operational notes: always validate and server-side sanitize or encode output (use HttpUtility.HtmlEncode for plain text; use a whitelist sanitizer or Markdown renderer if allowing formatting), use parameterized queries/stored procedures to avoid SQL injection, add an IsApproved flag and optional ExpiresAt for moderation/auto-expiry, and limit body length and submission rate to reduce spam. For performance show only the latest N items (SELECT TOP N ... ORDER BY CreatedAt DESC) and cache briefly, invalidating on new approved posts.

Start with this minimal pipeline (table + insert proc + Repeater for display) and then add sanitization, approval workflow, paging and caching as needed.

Recommended Answers

All 4 Replies

I would tend to agree that one viable option is to take the information from the textboxes, save them to a database table. Then use one of the asp.net controls in your toolsbox, such as a repeater, or a datalist and display the results on the page.

One question, those inputs are going to stay on the page only for the current user session or they must appear in the next visits as well?

In the first case, I'd save them in the Session, using an List<UserInput>. Where UserInput is a class with Title and Text properties.

In the second case, I'd save them on the DB and also would use an List<UserInput> for retrieving the saved itens from the DB.

Then, to show the saved itens(either from DB or Session) I suggest you to use a Repeater, as recommend by JorgeM.

The best thing about creating your own class to store the itens is that you can sofisticate it later, adding more information.

Thanks for the responses guys. I'll look into a repeater as I've never heard of that control before.

yes I want the items to stay on the home page for multiple visits for multiple users; not just the current user session. Essentially I want the inputs to stay up for days (I'll probably code something to limit the time they appear later) so other users that visit can read them as well.

I wanted to compare it to a "comments" section but I didn't want to explicitly say comments as I thought that might confuse someone.

I see, that's it them. You can create a UserComment class to hold all the data, including Title, Text, UserName, Comment DateTime and so on.

I suggest you start by defining your database structure. I mean, you probably already have a Users table, so you'll need to create an UserComment table, or something like that.

Once you have your database created, creating the Class is much more simpler.

Good luck.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.