Jump to content

Creating a forum

Recommended Posts

I'm pretty sure you'll fail if someone just gave you the code.Its not hard to write a forum. Here's a forum I wrote in ASP in less than 3 days:http://www.fstdt.com/forums/default.aspThe first step is setting up your tables. Minimally, you should have the following tables:

Users-----ID (autoincrement primary key)Username (varchar 20)Password (varchar 20)Forums------ID (autoincrement primary key)Title (varchar 20)LastPostID (int, foreign key = Posts.ID)Posts------ID (autoincrement primary key)ID_user (int, foreign key = Users.ID)ID_Forum (int, foreign key = Forums.ID)ID_Thread (int)Subject (varchar 100)Post (text)PostDate (datetime)

Create a default page that shows all of your forums.Create a login page that allows users to login, store a cookie (not a session variable) that tracks users userID and password.Create a forum page that shows all of your thread, filter by ID_Thread = 0 and ID_Forum = request("f").Create a thread page that shows all of the posts in a thread, filter by ID_Thread = request("t") or ID_post = request("t").If you know what you're doing, that amount of work should take you an hour at most.

Link to post
Share on other sites
Thx for your help.. but The problem is i totally noob to tis creating a forum.. I totally loss at wad should i type.. i even dunno how to start lo.. How ar?
A few things I want to know first:- When is your project due?- How long have you had to work on it?- What class are you taking?- Did you show up everyday for class?
Link to post
Share on other sites

I nid to submit the project by the end of July. i onli have about 2 mths to complete all.. Teacher every week will see individual's progress.This is an e-commerce project.. There is no lesson teaching how to create forum.. We are left to figure out ourselves on how to do.. Thats why i dun even noe how to start..

Link to post
Share on other sites

But this is my school project.. Compulsory to do ourself..Cannot take from the web.. So i die le.. Anyone noe how to setup an ecommerce website using ASP.NET can teach us? Willing to pay money for it.. But not too expensive la.. We students onli.. Project is due in 2mths time.. Pls help..

Link to post
Share on other sites

I'm not trying to be rude, but when your opening post reads "I need the codes for creating a forum..", that sounds like you're asking other people to do your homework for you. I don't have a problem helping people out, but I won't ever do their homework for them. (I remember once someone on this forum asked "Could someone give me the full ASP code to make MP3.com", and my jaw dropped at such an inane question.)As for setting up an e-commerce website, this online tutorial has an entire chapter dedicated e-commerce development.Now, I'll assume that you have no idea where to start when it comes to making an ASP.net forum. So, to start, do the following:- Download Visual Web Developer from Microsoft. VWD is a lite version of Visual Studio, its a kind of WYSIWYG editor. Normally, I would tell anyone developing websites to use a text editor, but unfortunately ASP.Net is really hard to write in a text editor without the Intellisense built into VWD.- Start Visual Web Developer and create new project -- try to name the project something other than "Website1", and don't use any of the personal starter kits. Make sure the box that says "Place Code In Seperate File" is selected. That box allows you to write whats called a "code behind", which seperates any scripting code from HTML.- The first page you'll get will look something like this:asp1ns7.th.gifThat the Visual Web Developer Interface. The red circle lets you edit your website with the WYSIWYG editor, the blue circle lets you edit the source code.If you know HTML, then most the source code should look familiar to you. You might notice the line at the top of the page is unfamiliar:

<%@ Page Language="VB" AutoEventWireup="false" CodeFile="Default.aspx.vb" Inherits="_Default" %>

That's a special ASP.Net directive, that tells the ASP.Net compiler. You don't have to worry about what any of those attributes mean.If you rightclick on either the Design or Source views and click "View Code", you get to a special window that looks like this:asp2cu8.th.gifThat window lets you edit the actual VB.net or C# code on your page.And now, just to get you started at light speed, here is a brief introduction to databases, the Gridview, and databinding:- Open MS Access and create a new a Access database. Make sure the database (it doesn't matter where the database is saved at.)- Create a new table with the following fields:-- ID (autoincrement)-- Title (varchar 50)-- Description (text / Memo)-- ForumOrder (integer / Numeric). This field will be used for controlling what order forums appear on the front page.- Save the table as "Forums" and add a few records to the database.(Note: I uninstalled MS Office a long time ago, so I don't use Access. I use SQL server. Most of the code will be identical to what you could use.)When you have your database set up, go back to Visual Web Developer, and click on your Solution Explorer. Right click the top-most item in the tree, and in the popup menu click "Add ASP.Net Folder", then select "App_Data". That's a special folder for holding data files like databases, XML, spreadsheets, etc. When the App_Data folder is created, right-click on it and choose "Add Existing File", then find the Access database you created and add it.Now you're read to start doing something constructive:- Go to design view and drag a gridview control onto the page (the gridview control is found under the "Data" tab). When you do that, a little window will pop up to the side asking you to chose a datasource. It should look something like this:asp3xs3.th.gif- Click "New Connection". A window will pop up asking you what kind of datasource to use. Choose "Access Datasource", and you should be able to find your database in the App_Code directory.- Continue through the wizard until you come across a window like this:asp4ll1.th.gif- You never ever want to specify columns to choose. Almost always, when you get to this point, you'll click the "Specify custom SQL statement or stored procedure" option button. Click that button, then hit next. You'll taken to a window where you can enter your own SQL statement. In that box, copy/paste the following statement:

Select ID, Title, Description From Forums ORDER BY ForumOrder

- Click next. You can test your query if you want; odds are, if you've done everything I've said correctly, then your query should work fine. Click finish.- You'll notice after you click finish that your Gridview changed its appearance somewhat. That's because the Gridview is set up to automatically generate columns and column data... unless you specify a different default template, which you'll almost always do from this point foward.Now, you just want to change the appearance of your gridview. I like to work with my gridview's appearance in Source code view, so switch to source view, and you'll notice that VWD has added some code to your page. It will look something like this:

<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" DataSourceID="sqlForum">			<Columns>				<asp:BoundField DataField="ID" HeaderText="ID" InsertVisible="False" ReadOnly="True"					SortExpression="ID" />				<asp:BoundField DataField="Title" HeaderText="Title" SortExpression="Title" />				<asp:BoundField DataField="Description" HeaderText="Description" SortExpression="Description" />			</Columns>		</asp:GridView>

I've deleted the BoundField columns, and I've replaced them with a single TemplateField column for more control. My Gridview now looks like this:

<asp:GridView ID="GridView1" runat="server"		AutoGenerateColumns="False" DataSourceID="sqlForum" ShowHeader="False"		Width="95%"		HorizontalAlign="Center">			<Columns>				<asp:TemplateField>					<ItemTemplate>						<asp:Panel runat="server" ID="pnlTitle"						style="background : #FF0099; border : solid 1px #FF99FF; vertical-align : middle;">							<asp:HyperLink							style="color : #FFFFFF; font-family : verdana; font-size : 12pt;							font-weight : bold; margin : 20px 20px 20px 20px; margin-left : 10px;"							runat="server"							Text='<%# Eval("Title") %>'							NavigateUrl='<%# String.Format("forum.aspx?f={0}", Eval("ID")) %>' />						</asp:Panel>						<asp:Panel runat="server" ID="pnlDescription"						style="background : #EEEEEE; color : #FF0099;">							<asp:Label runat="server"							Text='<%# Eval("Description") %>'							style="margin : 4px 4px 4px 4px; margin-left : 20px; margin-bottom : 0px;" />						</asp:Panel>					</ItemTemplate>				</asp:TemplateField>			</Columns>		</asp:GridView>

Your front page is basically done at this point. Press the F5 key to run your project and see how it looks in your browser. A message box will pop up asking you if you want to edit your web.config file for debugging, click yes. IE should pop up and you should see your finished product.

Link to post
Share on other sites

The next step is creating a page for displaying threads for your forum. I'll leave it up to you to figure out the threads page.Believe me, 2 months is plenty of time to learn ASP.net. You can learn everything you need to learn to make a forum in about 2 weeks. After you learn ASP.Net, it shouldn't take more than 2 or 3 days to put together a working forum.Oh, and if you have an error on your page, for the love the mother goddess, don't say "I have an error! Please help me!".Visual Web Developer is very good at helping you solve errors: there will usually be an "errors" box. When you doubleclick an error, it will take you to the line of code with an error, and it will usually have a descriptive error message. A typical error message is:

Validation (ASP.Net): Element 'asp:GridView' is missing required attribute 'runat'.
That means my Gridview control is missing its "runat" attribute. When I doubleclick on the error, it takes me to the following line of code:
<asp:GridView ID="GridView1" 		AutoGenerateColumns="False" DataSourceID="sqlForum" ShowHeader="False"		Width="95%"		HorizontalAlign="Center">

I can fix that line of code by adding the "runat" attribute:

<asp:GridView ID="GridView1" runat="server"		AutoGenerateColumns="False" DataSourceID="sqlForum" ShowHeader="False"		Width="95%"		HorizontalAlign="Center">

And the error goes away.You should try to solve errors on your own before you ask for help.If you're genuinely stumped, then do the following:- Copy and paste the error into a new post.- Copy the source code that is causing the error. DO NOT copy/paste the entire page unless you absolutely have to.

Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Create New...