Building a Web Forum

Last post 06-29-2009 3:28 PM by stlarmon. 6 replies.

Sort Posts:

  • Building a Web Forum

    06-15-2009, 8:48 PM
    • Member
      point Member
    • Paulie222
    • Member since 03-31-2009, 4:06 AM
    • Jacksonville, FL
    • Posts 24

     I have a little bit of trouble figuring out why I am getting these error messages. Here is the error messages and then the code will follow behind it.The code is taken directly out of the book "ASP.NET 2.0 Everyday Applications for DUMMIES". Any help is greatly appreciated. Thank you.

    --------------------------------------------------------------------------------line--column--------------

    Error    13    Name 'ForumRepeater' is not declared.                                                                                                    37    9   
    Error    14    Name 'ForumRepeater' is not declared.                                                                                                    39    9   
    Error    15    Handles clause requires a WithEvents variable defined in the containing type or one of its base types.                                                                                                        45    21

     

    Forums/Default.aspx

     

    1    <%@ Page Title="" Language="VB" MasterPageFile="~/MasterPage.master" AutoEventWireup="false" CodeFile="Default.aspx.vb" Inherits="Forums_Default" %>
    2
    3 <asp:Content ID="Content1" ContentPlaceHolderID="head" Runat="Server">
    4 <style type="text/css">
    5 .style16
    6 {
    7 width: 100%;
    8 }
    9 </style>
    10 </asp:Content>
    11 <asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" Runat="Server">
    12 <table border="0">
    13 <asp:Repeater ID="ForumRepeater" runat="server">
    14 <ItemTemplate>
    15 <tr>
    16 <td>
    17 <asp:Label ID="lblForumName" runat="server" Text='<% #Eval ("name") %>'>
    18 </td>
    19 </tr>
    20 <asp:Repeater ID="TopicRepeater" runat="server">
    21 <ItemTemplate>
    22 <tr><td>
    23 <asp:LinkButton ID="LinkTopicName" runat="server" Text='<% #Eval ("name")%>'
    24 PostBackUrl='<% #Eval ("topicid", "Threads.aspx?topic={0}")%>'>
    25 --
    26 <asp:Label ID="lblTopicDesc" runat="server" Text="<% #Eval ("description") %>">
    27 </td></tr>
    28 </ItemTemplate>
    29 </asp:Repeater>
    30 </ItemTemplate>
    31 </asp:Repeater>
    32 </table>
    33 </asp:Content>
    34

      Forum/Default.aspx.vb

      

    1    Imports System.Web.Configuration
    2 Imports System.Data.SqlClient
    3 Imports System.Data
    4
    5 Partial Class Forums_Default
    6 Inherits System.Web.UI.Page
    7
    8 Private ds As DataSet
    9
    10 Protected Sub Page_Load( _
    11 ByVal sender As Object, _
    12 ByVal e As System.EventArgs) _
    13 Handles Me.Load
    14 Dim con As String _
    15 = WebConfigurationManager _
    16 .ConnectionStrings("ForumConnectionString") _
    17 .ConnectionString
    18 ds = New DataSet()
    19
    20 'fill the Forums table
    21 Dim sel As String _
    22 = "SELECT [forumid], [name] " _
    23 + "FROM Forums " _
    24 + "ORDER BY [name]"
    25 Dim da As SqlDataAdapter _
    26 = New SqlDataAdapter(sel, con)
    27 da.Fill(ds, "Forums")
    28
    29 'fil the Topics Table
    30 sel = "SELECT [forumid], [topicid], " _
    31 + "[name], [description] " _
    32 + "ORDER BY [name]"
    33 da = New SqlDataAdapter(sel, con)
    34 da.Fill(ds, "Topics")
    35
    36 ' bind the Forum Repeater
    37 ForumRepeater.datasource = ds.Tables("Forums") _
    38 .DefaultView
    39 ForumRepeater.DataBind()
    40 End Sub
    41
    42 Protected Sub
    ForumRepeater_ItemDataBound( _
    43 ByVal sender As Object, _
    44 ByVal e As RepeaterItemEventArgs) _
    45 Handles ForumRepeater.ItemDataBound
    46 Dim r As Repeater
    47 r = e.Item.FindControl("TopicRepeater")
    48
    49 Dim drv As DataRowView
    50 drv = e.Item.DataItem
    51 Dim forumid As String = drv("forumid")
    52
    53 Dim dv As DataView
    54 dv = ds.Tables("Topics").DefaultView
    55 dv.RowFilter = "forumid=" + forumid
    56
    57 r.DataSource = dv
    58 r.DataBind()
    59 End Sub
    60 End Class

    61
      
  • Re: Building a Web Forum

    06-15-2009, 11:27 PM
    • Participant
      834 point Participant
    • abinashpatra
    • Member since 02-23-2009, 7:06 AM
    • Bangalore
    • Posts 243

    Hello,

    Have you checked the designer file if the declaration is present? Go to the FileName.aspx.designer.cs file and check if the declaration is present or not. Else manually put.

    Best Regards,
    Abinash Patra

    Please mark the post as answer, if you find this useful.

  • Re: Building a Web Forum

    06-16-2009, 3:16 PM
    • Member
      point Member
    • Paulie222
    • Member since 03-31-2009, 4:06 AM
    • Jacksonville, FL
    • Posts 24

     Isn't the repeater declared in line 13 of the aspx page?

     

    13       <asp:Repeater ID="ForumRepeater" runat="server">
     
    I don't know what you mean by designer file, but I copied the code right out of the book. 
    And just so I understand, even if I was to declare the ForumRepeater manually would I just put it as:
     
     
    Dim ForumRepeater As String
      

     

  • Re: Building a Web Forum

    06-17-2009, 2:37 PM
    • Participant
      856 point Participant
    • stlarmon
    • Member since 06-10-2008, 5:56 PM
    • New York, USA
    • Posts 144

    Usually this will happen if you rename a page and don't change the inherits (Inherits="Forums_Default") to match the Class declaration in the Code behind.  However, yours all seem to match, which leads me to believe that you are using a default namespace and not prefexing it in the inherits.  There are two ways to fix if that is the issue.

    1)  Go to the Visual Studio Property Pages for your Web App (Right Click on the Project Name) and delete the text under Root Namespace

    OR

    2) Prefix your inherits statement with the Root Namespace you're using (if Root Namespace was Test than Inherits="Test.Forums_Default" )

    Steve
  • Re: Building a Web Forum

    06-18-2009, 7:53 AM
    • Participant
      834 point Participant
    • abinashpatra
    • Member since 02-23-2009, 7:06 AM
    • Bangalore
    • Posts 243

    Hello,

    I hope you are using asp.net 2.0. In 2.0 When you create Web Page below files are created.

    File.aspx

    File.aspx.cs

    File.aspx.designer.cs

    File.aspx.resx

    Am refering to the 3rd file. The designer. This contains the declarations for all conrtols. Do you have a declaration like this?

    protected global::System.Web.UI.WebControls.repeater ForumRepeater;

    Am suspecting this. Also am little more sure on this issue, as you have told that you have copied the content from the book directly.

     

    Just check that and revert.

    Best Regards,
    Abinash Patra

    Please mark the post as answer, if you find this useful.

  • Re: Building a Web Forum

    06-23-2009, 8:38 PM
    • Member
      point Member
    • Paulie222
    • Member since 03-31-2009, 4:06 AM
    • Jacksonville, FL
    • Posts 24

     Actually the book had the inherits=_Default". So I changed that and still nothing happened. I don't really get what you mean in your first statement about the root namespace. According to the dummies book the namespace should have been imported when I called the statements:

    Imports System.Web.Configuration
    Imports System.Data.SqlClient
    Imports System.Data

     

    Does this have to do anything with the Repeater ID="ForumRepeater" not being declared?

  • Re: Building a Web Forum

    06-29-2009, 3:28 PM
    • Participant
      856 point Participant
    • stlarmon
    • Member since 06-10-2008, 5:56 PM
    • New York, USA
    • Posts 144

    Forum Repeater is being declared.  This is signified by an ID and the appropriate runat server <asp:Repeater ID="ForumRepeater" runat="server">
    This seems more like the HTML and The Code Behind not wiring up together.

    The Imports statements let you use classes belonging to another Namespace.  The Root NameSpace is the NameSpace for your project.  You can view your Root NameSpace by Right-Clicking the Project Name in Solution Explorer and Selecting Property Pages.  This NameSpace should be the prefix for your inherits statement.

    Steve
Page 1 of 1 (7 items)