Wrox Programmer Forums
|
ASP.NET 1.1 As of 10/6/2005, this forum is locked as part of the reorganization described here: http://p2p.wrox.com/topic.asp?TOPIC_ID=35394. No posts have been deleted. Open ongoing discussions from the last week have been moved to either ASP.NET 1.0 and 1.1 Beginners http://p2p.wrox.com/asp-net-1-0-1-1-basics-60/ or ASP.NET 1.0 and 1.1 Professional. http://p2p.wrox.com/forum.asp?FORUM_ID=50. See my sticky post inside for more.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the ASP.NET 1.1 section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old July 19th, 2004, 01:40 PM
Imar's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
Default

Hi Edward,

I think I see what the problem is. You're mixing non VS.NET code with VS.NET code.
So the ASPX looks like an ordinary ASPX page that expects inline code, and hence has no inherits or Codebehind attribute. Yet you do write your code in a code behind file.

To know what class the current page must be connected to, you'll need something like this at the top of the page:

<%@ Page language="VB" Codebehind="YourPage.aspx.cs" AutoEventWireup="false" Inherits="YourNameSpace.YourPage" %>

At run time, the page will be loaded and will inherit from your page class (that in turn is derived from Page).
Right now, the class is compiled to the assembly, and that's about it. There is no connection between the page and the compiled class, so none of the code defined in that class will ever run.

The Codebehind is needed for Visual Studio to relate the ASPX and the Code Behind file.

HtH,

Imar
---------------------------------------
Imar Spaanjaars
Everyone is unique, except for me.
While typing this post, I was listening to: Ode To A D.J. (Mark Gambler Mix) by Art Of Noise (Track 6 from the album: The Fon Mixes) What's This?
 
Old July 20th, 2004, 11:24 AM
Authorized User
 
Join Date: Jun 2004
Posts: 44
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hi Imar, Yes that makes a big difference to the operation of that page, however, I am still getting a popup error message saying "There were errors building the project. Do you want to contiue with the preview anyway?" If I select yes I can now see that the DataGrid has been loaded with the four records!
Now if I am viewing a page in a project using the browser, from the page mouse right click menu, do all other pages have to compile as well or is it local to that page?
I have an error in the default page from chapter 11 page 426 in the line:
e.cell.cssClass = "selecteddate"
were "'cssClass' is not a member of 'System.Web.UI.WebControls.TableCell'" this is another one of these lines from the back code "'#Region' Web Form Designer Generated Code" like but not the same as "Protected WithEvents ----" What should I be using instead of "WithEvents" and how do I find the options that are available for use in this location?

Sorry to keep asking these questions, I know that this book is not describing a VS project.
Many thanks as always,

Edward.

 
Old July 20th, 2004, 11:51 AM
Imar's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
Default

I am not 100% sure how VS.NET handles this, but when you view a page in the browser, it will try to compile the entire application. Apparently (that's what I am not sure about), when you click yes, it will still create the assembly, and ignore the pages that didn't compile....

I also don't understand the other error. CssClass *is* a member of TableCell as it inherits that from WebControl (see: http://msdn.microsoft.com/library/de...mberstopic.asp)

I don't have the book, so I also don;t have the code you are referring to. Maybe you should post the code for the entire page.

When you edit or create pages in VS.NET, how do you add the pages? Do you create a text file, rename it to ASPX and then edit it, or do you use the Add New dialog in VS.NET??

Imar
---------------------------------------
Imar Spaanjaars
Everyone is unique, except for me.
 
Old July 21st, 2004, 05:56 AM
Authorized User
 
Join Date: Jun 2004
Posts: 44
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hi Imar, I have included the full code for Default.aspx both back (where the error is located) and front pages. The code is getting a bit long by the time we reach page 426 in the book, so I have added a selection from the 'Sub EventCalendar_DayRender()' procedure to home in on the offending line.
If I hover the mouse over the e.cell.cssclass I get a tip which reads "'cssClass' is not a member of 'System.Web.UI.WebControls.TableCell'" I think this another case where there is a failure of communication between the front and back pages which is possibly why it claims that cssclass is **not** a member.
Strange thing is if I delete this line the code runs without an error being notified (however I have lost the red 3 dot lines round the selected dates).

When I create pages in VS.NET I have been adding a new WebForm, naming it then typing the code (because I find I can appreciate what it is doing better than copying it in from another source) I edit it in the VS application user interface on screen (API) (need another screen dump for clarification)
I have used Notepad in the past, when working with ASP and InterDev6 but this required the new .asp file added from source into the project from where it would be written to the root directory, but not for VS.NET
I have to say that I rarely used the designer in InterDev preferring to write HTML or VB in the script, into the code page, which in turn maybe why I have not appreciated the extent that VS.NET automatically writes code for the developer and why I have been experiencing difficulty linking the back page. If I write code in the front page without using the designer the "Protected WithEvents links" sometimes are not written.
Thanks again as always for your help,

Edward.

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~
Selected code in Default.aspx back Page where error is located

    Sub EventCalendar_DayRender(ByVal sender As Object, ByVal e As DayRenderEventArgs)

        If Not Cache("DateList")(e.Day.Date) Is Nothing Then

            e.Cell.ccsClass = "selecteddate" <-- code on the LHS of '=' is underlined
            ' The following line will exist in your code if you completed the exercisees
            ' at the end of the last chapter
            e.Day.IsSelectable = True
        Else
            'This line of code is part of the solution to one of the exercises at the end
            ' of chapter 10
            e.Day.IsSelectable = False
        End If
    End Sub

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~
Total code in Default.aspx Back Page
Public Class WebForm1
    Inherits System.Web.UI.Page
    Public DateList As New System.Collections.Hashtable

#Region " Web Form Designer Generated Code "

    'This call is required by the Web Form Designer.
    <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()

    End Sub
    Protected WithEvents lnkTeams As System.Web.UI.WebControls.HyperLink
    Protected WithEvents lnkPlayers As System.Web.UI.WebControls.HyperLink
    Protected WithEvents lnkGames As System.Web.UI.WebControls.HyperLink
    Protected WithEvents lnkResults As System.Web.UI.WebControls.HyperLink
    Protected WithEvents EventCalendar As System.Web.UI.WebControls.Calendar
    Protected WithEvents MatchesByDateList As System.Web.UI.WebControls.Repeater
    Protected WithEvents pnlFixtureDetails As System.Web.UI.WebControls.Panel
    Protected WithEvents lblRegister As System.Web.UI.WebControls.Label
    Protected WithEvents txtEmailAddress As System.Web.UI.WebControls.TextBox
    Protected WithEvents btnRegister As System.Web.UI.WebControls.Button
    Protected WithEvents ValidEmail As System.Web.UI.WebControls.RegularExpressionValidat or
    Protected WithEvents lnkMerchandise As System.Web.UI.WebControls.HyperLink
    Protected WithEvents lnkChat As System.Web.UI.WebControls.HyperLink
    Protected WithEvents ddlTheme As System.Web.UI.WebControls.DropDownList
    Protected WithEvents btnApplyTheme As System.Web.UI.WebControls.Button
    Protected WithEvents chkRememberStylePref As System.Web.UI.WebControls.CheckBox

    'NOTE: The following placeholder declaration is required by the Web Form Designer.
    'Do not delete or move it.
    Private designerPlaceholderDeclaration As System.Object

    Private Sub Page_Init(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Init
        'CODEGEN: This method call is required by the Web Form Designer
        'Do not modify it using the code editor.
        InitializeComponent()
    End Sub

#End Region

    Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

        If Not Page.IsPostBack Then

            If Session("SelectedCss") Is Nothing Then
                If Request.Cookies("PreferredCss") Is Nothing Then
                    Session("SelectedCss") = "WroxUnited.css"
                Else
                    Session("SelectedCss") = Request.Cookies("Preferred.Css").Value

                End If
            End If

        End If

        ' we need to run this each time the page is loaded, so that
        ' after a date is selected and the page is posted back, the
        ' active dates will still be highlighted.
        If Cache("DateList") Is Nothing Then
            Dim DateReader As System.Data.IDataReader
            DateReader = Dates()

            While DateReader.Read()

                DateList(DateReader("Date")) = DateReader("Date")

            End While
            DateReader.Close()
            Cache.Insert("DateList", DateList, Nothing, DateTime.Now.AddMinutes(1), _
                            Cache.NoSlidingExpiration)

            'Response.Write("Added to cache")
            'Else
            'Response.Write("Already in chache - nothing added")
        End If


        If Not Request.Cookies("EmailRegister") Is Nothing Then

            txtEmailAddress.Visible = False
            lblRegister.Text = "You have registered for email updates"
            btnRegister.Visible = False

        End If

    End Sub

    Function Dates() As System.Data.IDataReader
        Dim connectionString As String = _
           ConfigurationSettings.AppSettings("ConnectionStrin g")

        Dim dbConnection As System.Data.IDbConnection = _
           New System.Data.OleDb.OleDbConnection(connectionString )

        Dim queryString As String = _
           "SELECT [Games].[Date], [Games].[GameID] FROM [Games]"
        Dim dbCommand As System.Data.IDbCommand = _
           New System.Data.OleDb.OleDbCommand
        dbCommand.CommandText = queryString
        dbCommand.Connection = dbConnection

        dbConnection.Open()
        Dim dataReader As System.Data.IDataReader = _
           dbCommand.ExecuteReader(System.Data.CommandBehavio r.CloseConnection)

        Return dataReader
    End Function

    Sub EventCalendar_DayRender(ByVal sender As Object, ByVal e As DayRenderEventArgs)

        If Not Cache("DateList")(e.Day.Date) Is Nothing Then

            e.Cell.ccsClass = "selecteddate"
            ' The following line will exist in your code if you completed the exercisees
            ' at the end of the last chapter
            e.Day.IsSelectable = True
        Else
            'This line of code is part of the solution to one of the exercises at the end
            ' of chapter 10
            e.Day.IsSelectable = False
        End If
    End Sub

    Sub EventCalendar_SelectionChanged(ByVal sender As Object, ByVal e As EventArgs)

        pnlFixtureDetails.Visible = True
        MatchesByDateList.DataSource = _
          GamesBydate(EventCalendar.SelectedDate.ToShortDate String)
        MatchesByDateList.DataBind()

    End Sub

    Function Venue(ByVal OpponentLocation As String, ByVal MatchVenue As Integer) As String

        If MatchVenue = 1 Then
            ' match is at home
            Return "Wroxville"
        Else
            Return OpponentLocation

        End If

    End Function

    Function GamesByDate(ByVal [date] As Date) As System.Data.IDataReader
        Dim connectionString As String = ConfigurationSettings.AppSettings("ConnectionStrin g")
        Dim dbConnection As System.Data.IDbConnection = New System.Data.OleDb.OleDbConnection(connectionString )

        Dim queryString As String = "SELECT [Teams].[TeamName], [Opponents].[OpponentName], [Games].[Location], [Oppon" & _
      "ents].[OpponentLocation] FROM [Teams], [Opponents], [Games] WHERE (([Opponents]." & _
      "[OpponentID] = [Games].[OpposingTeam]) AND ([Teams].[TeamID] = [Games].[WroxTeam" & _
      "]) AND ([Games].[Date] = @Date))"
        Dim dbCommand As System.Data.IDbCommand = New System.Data.OleDb.OleDbCommand
        dbCommand.CommandText = queryString
        dbCommand.Connection = dbConnection

        Dim dbParam_date As System.Data.IDataParameter = New System.Data.OleDb.OleDbParameter
        dbParam_date.ParameterName = "@Date"
        dbParam_date.Value = [date]
        dbParam_date.DbType = System.Data.DbType.DateTime
        dbCommand.Parameters.Add(dbParam_date)

        dbConnection.Open()
        Dim dataReader As System.Data.IDataReader = dbCommand.ExecuteReader(System.Data.CommandBehavio r.CloseConnection)

        Return dataReader
    End Function

    Function CheckFanEmailAddress(ByVal fanEmail As String) As Boolean
        Dim connectionString As String = _
          ConfigurationSettings.AppSettings("connectionStrin g")
        Dim dbConnection As System.Data.IDbConnection = _
          New System.Data.OleDb.OleDbConnection(connectionString )
        Dim queryString As String = _
          "SELECT COUNT( [Fans].[FanEmail] ) FROM [Fans]" & _
          "WHERE ([Fans].[FanEmail] = @FanEmail)"
        Dim dbCommand As System.Data.IDbCommand = _
          New System.Data.OleDb.OleDbCommand
        dbCommand.CommandText = queryString
        dbCommand.Connection = dbConnection

        Dim dbParam_fanEmail As System.Data.IDbDataParameter = _
          New System.Data.OleDb.OleDbParameter
        dbParam_fanEmail.ParameterName = "@FanEmail"
        dbParam_fanEmail.Value = fanEmail
        dbParam_fanEmail.DbType = System.Data.DbType.String
        dbCommand.Parameters.Add(dbParam_fanEmail)
        Dim Result As Integer = 0
        dbConnection.Open()
        Try
            Result = dbCommand.ExecuteScalar
        Finally
            dbConnection.Close()
        End Try

        If Result > 0 Then
            Return True
        Else
            Return False
        End If
    End Function

    Function AddNewFanEmail(ByVal fanEmail As String) As Integer
        Dim connectionString As String = _
          ConfigurationSettings.AppSettings("connectionStrin g")
        Dim dbConnection As System.Data.IDbConnection = _
          New System.Data.OleDb.OleDbConnection(connectionString )
        Dim queryString As String = "INSERT INTO [Fans] ([FanEmail])" & _
                                    "VALUES (@FanEmail)"
        Dim dbCommand As System.Data.IDbCommand = _
          New System.Data.OleDb.OleDbCommand
        dbCommand.CommandText = queryString
        dbCommand.Connection = dbConnection

        Dim dbParam_fanEmail As System.Data.IDbDataParameter = _
          New System.Data.OleDb.OleDbParameter
        dbParam_fanEmail.ParameterName = "@FanEmail"
        dbParam_fanEmail.Value = fanEmail
        dbParam_fanEmail.DbType = System.Data.DbType.String
        dbCommand.Parameters.Add(dbParam_fanEmail)

        Dim rowsAffected As Integer = 0
        dbConnection.Open()
        Try
            rowsAffected = dbCommand.ExecuteScalar
        Finally
            dbConnection.Close()
        End Try

        Return rowsAffected
    End Function

    Sub btnRegister_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnRegister.Click
        Dim FanEmail As String = txtEmailAddress.Text

        ' Check whether the email address is already registered
        ' If not, we need to register it by calling the AddNewFanEmail() method
        If CheckFanEmailAddress(FanEmail) = False Then

            AddNewFanEmail(FanEmail)

        End If

        ' Email has been registered, so update the display and attempt to set a cookie
        txtEmailAddress.Visible = False
        lblRegister.Text = "You have successfully registered for email updates"
        btnRegister.Visible = False

        Dim EmailRegisterCookie As New HttpCookie("EmailRegister")
        EmailRegisterCookie.Value = FanEmail
        EmailRegisterCookie.Expires = Now.AddSeconds(20)
        Response.Cookies.Add(EmailRegisterCookie)

    End Sub

    Sub btnApplyTheme_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnApplyTheme.Click

        Session("SelectedCss") = ddlTheme.SelectedItem.Value

        If chkRememberStylePref.Checked Then

            Dim CssCookie As New HttpCookie("PreferredCss")
            CssCookie.Value = ddlTheme.SelectedItem.Value
            CssCookie.Expires = Now.AddSeconds(20)
            Response.Cookies.Add(CssCookie)

        End If
    End Sub
End Class
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~
Total code in Default.aspx Front Page

 
Old July 21st, 2004, 06:04 AM
Authorized User
 
Join Date: Jun 2004
Posts: 44
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hi Imar, have I passed the capacity of the above textbox?
Here is the front page.

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~
Total code in Default.aspx Front Page
<%@ Page Language="vb" AutoEventWireup="false" Codebehind="Default.aspx.vb" Inherits="WroxUnited1.WebForm1"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
    <HEAD>
        <title>Wrox United</title>
        <meta content="Microsoft Visual Studio .NET 7.1" name="GENERATOR">
        <meta content="Visual Basic .NET 7.1" name="CODE_LANGUAGE">
        <meta content="JavaScript" name="vs_defaultClientScript">
        <meta content="http://schemas.microsoft.com/intellisense/ie5" name="vs_targetSchema">
        <link id="css" href='<%=Session("SelectedCss") %>' type="text/css" rel="stylesheet" >
    </HEAD>
    <body>
        <form id="Form1" method="post" runat="server">
            <H1>Wrox United</H1>
            <table style="WIDTH: 800px">
                <tr>
                    <td width="800">
                        <h2>Welcome to the Wrox United Website!<br>
                            Please select one of the following:</h2>
                    </td>
                    <td width="220">
                        <asp:Label id="lblRegister" runat="server">Register for email updates</asp:Label>
                        <asp:TextBox id="txtEmailAddress" runat="server"></asp:TextBox>
                        <asp:Button id="btnRegister" runat="server" Text="Register" Width="60px"></asp:Button>
                        <asp:RegularExpressionValidator id="ValidEmail" runat="server" ErrorMessage="Please enter a valid email address"
                            ControlToValidate="txtEmailAddress" ValidationExpression="\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*"></asp:RegularExpressionValidator>
                    </td>
                </tr>
            </table>
            <table style="VERTICAL-ALIGN: top; WIDTH: 800px">
                <tr>
                    <TD style="WIDTH: 216px">
                        <P><asp:hyperlink id="lnkTeams" runat="server" NavigateUrl="Teams.aspx">Teams</asp:hyperlink></P>
                        <P><asp:hyperlink id="lnkPlayers" runat="server" NavigateUrl="Players.aspx">Players</asp:hyperlink></P>
                        <P><asp:hyperlink id="lnkGames" runat="server" NavigateUrl="Default.aspx">Upcoming Games</asp:hyperlink></P>
                        <P><asp:HyperLink id="lnkResults" runat="server" NavigateUrl="Default.aspx">Results</asp:HyperLink></P>
                        <P><asp:HyperLink id="lnkMerchandise" runat="server" NavigateUrl="Merchandise.aspx">Merchandise</asp:HyperLink></P>
                        <P><asp:HyperLink id="lnkChat" runat="server" NavigateUrl="Chat.aspx">Chat</asp:HyperLink></P>

                        <br>
                        <br>
                        <p>
                            Choose a theme:
                            <br>
                            <asp:DropDownList ID="ddlTheme" Runat="server">
                                <asp:ListItem Value="WroxUnited.css" Selected="True">Home Kit</asp:ListItem>
                                <asp:ListItem Value="WroxUnited2.css">Away Kit</asp:ListItem>
                            </asp:DropDownList>
                            <asp:Button ID="btnApplyTheme" OnClick="btnApplyTheme_Click" Runat="server" Text="Apply"></asp:Button>
                            <br>
                            <asp:CheckBox ID="chkRememberStylePref" Runat="server" Text="Remember Preferences"></asp:CheckBox>
                        </p>
                    </TD>
                    <TD style="WIDTH: 288px; VERTICLE-ALIGN: top" width="288">&nbsp;</TD>
                    <TD style="WIDTH: 250px; VERTICLE-ALIGN: top">
                        <asp:Calendar id="EventCalendar" runat="server" OnSelectionChanged="EventCalendar_SelectionChanged "
                            OnDayRender="EventCalendar_DayRender" CssClass="calendar">
                            <DayStyle CssClass="normaldate"></DayStyle>
                            <OtherMonthDayStyle CssClass="othermonthdate"></OtherMonthDayStyle>
                        </asp:Calendar>
                        <P>
                            <asp:Panel id="pnlFixtureDetails" Visible="False" Runat="server">
                                <asp:Repeater id="MatchesByDateList" Runat="server">
                                    <HeaderTemplate>
                                        <span style="width:110px;height:25px">Date: </span><span style="width:135px;height:25px">
                                            <%# EventCalendar.SelectedDate.ToShortDateString %>
                                        </span>
                                        <br />
                                    </HeaderTemplate>
                                    <ItemTemplate>
                                        <span style="width:110px">Wrox Team</span> <span style="width:135px">
                                            <%# Container.DataItem("TeamName") %>
                                        </span>
                                        <br />
                                        <span style="width:110px">Opposing Team</span> <span style="width:135px">
                                            <%# Container.DataItem("OpponentName") %>
                                        </span>
                                        <br />
                                        <span style="width:110px">Venue</span> <span style="width:135px">
                                            <%# venue(Container.DataItem("OpponentLocation"), _
                                          Container.DataItem("Location")) %>
                                        </span>
                                        <br />
                                    </ItemTemplate>
                                    <SeparatorTemplate>

                                        </span>
                                    </SeparatorTemplate>
                                </asp:Repeater>
                            </asp:Panel></P>
                    </TD>
                </tr>
            </table>
        </form>
    </body>
</HTML>


 
Old July 21st, 2004, 02:05 PM
Imar's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
Default

Hi Edward,

A bit late response, as I am pretty tied up with my work at the moment. So, you have solved this problem in the mean time.

Anyway, over here we have a children's game called "I see I see what you cannot see" (or something along those lines). And I must admit, I didn't see it for a while as well....

Look at this:
Code:
e.Cell.ccsClass = "selecteddate" <-- code on the LHS of '=' is underlined
and this:
Code:
e.Cell.cssClass = "selecteddate" <-- code on the LHS of '=' is underlined
See the difference? It's CssClass, not CcsClass.... ;)

In your initial post, you mentioned CssClass which is the correct property. As soon as I changed it, the page ran fine.

Cheers,

Eagle Eye Imar ;)
---------------------------------------
Imar Spaanjaars
Everyone is unique, except for me.
 
Old July 23rd, 2004, 08:14 AM
Authorized User
 
Join Date: Jun 2004
Posts: 44
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hi Imar, you are absolutely correct, I guess I must be getting too close to it to see simple typos like this! Funny thing is that I have had this line of code on and of off this page a number of times, initially when the value e ( System.EventArgs) was written followed by the dot it brings down a menu where Cell & CssClass are selected. When I removed the code I add it to a Notepad file so that I won't forget what I have removed and can copy it back if necessary - it's a mystery how it got changed, really must be more carefull!!
Many thanks to Eagle Eye Imar ;)
your with appreciation and thanks,

Edward.










Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.