0

I have the following pages, but on the verify page, it is saying these are not defined: content = "Name: " + result.FName + "<br>" + "E-mail: " + result.EmailOption + "<br>" + "Gender: " + result.GenderOption <br>

Here are the pages:

addentry.aspx:

<%@ Page Language="VB" ClassName="SenderClass" debug="true" %>

<script runat="server">

    ' Readonly property for first name
    Public ReadOnly Property FName() As String
        Get
            Return FirstName.Text
        End Get
    End Property

    ' Readonly property for last name
    Public ReadOnly Property LName() As String
        Get
            Return LastName.Text
        End Get
    End Property
   
    ' Readonly property for gender
    Public ReadOnly Property GenderOption() As String
        Get
            Return Gender.Text
        End Get
    End Property

    ' Readonly property for age
    Public ReadOnly Property AgeOption() As String
        Get
            Return Age.Text
        End Get
    End Property
 
    ' Readonly property for e-mail
    Public ReadOnly Property EmailOption() As String
        Get
            Return Email.Text
        End Get
    End Property
    
    'Event to transfer page control to Verify.aspx
    Sub Page_Transfer(ByVal sender As Object, ByVal e As EventArgs)
        Server.Transfer("Verify.aspx")
    End Sub
    </script>
    
<%@ Import Namespace="System.IO" %>
<html>

<script runat="server">
    
    Sub Verify(ByVal Sender As Object, _
      ByVal B As EventArgs)
        Dim GBPeople As String
        GBPeople = _
            "gbpeople.txt"
        My.Computer.FileSystem.WriteAllText(GBPeople, _
           FirstName.Text & "<br>", True)
        My.Computer.FileSystem.WriteAllText(GBPeople, _
           LastName.Text & "<br>", True)
        My.Computer.FileSystem.WriteAllText(GBPeople, _
           Gender.SelectedItem.Text & "<br>", True)
        My.Computer.FileSystem.WriteAllText(GBPeople, _
           Email.Text & "<br><br>", True)
        
        Response.Redirect("Verify.aspx")
    End Sub
    </script>
    <head><title></title></head>
<body>
<h1> Sign Our Guestbook</h1>
<form runat="server">
First Name: <br />
<asp:TextBox id="FirstName" runat="server" /><br />
Last Name:<br />
<asp:textbox ID="LastName" runat="server" /><br />
Gender:<br />
<asp:RadioButtonList ID="Gender" runat="server">
    <asp:ListItem Selected="True">Male</asp:ListItem>
    <asp:ListItem>Female</asp:ListItem>
</asp:RadioButtonList><br />
Age:<br />
<asp:textbox id="age" runat="server"/><br />
Email Address:<br />
<asp:textbox id="Email" runat="server"/><br />
<asp:Button ID="AddMe" Text="Add Me!" runat="server" OnClick="Verify" /><br />
</form>
</body>
</html>

verify.aspx:

<%@ Page Language="VB" debug="true" ClassName="SenderClass" %>
<%@ Reference Page="addentry.aspx" %>

<script runat="server">
     
    Dim result As SenderClass

	Sub Page_load(obj as Object, e as EventArgs)
		Dim content As String

        If Not IsPostBack Then
            result = CType(Context.Handler, SenderClass)
            content = "Name: " + result.FName + "<br>" + "E-mail: " + result.EmailOption + "<br>" + "Gender: " + result.GenderOption
            Label1.Text = content
        End If
    End Sub

    Protected Sub Confirm_Click(ByVal sender As Object, ByVal e As System.EventArgs)

    End Sub
</script>

<html>
<head runat="server">
    <title>Untitled Page</title>
</head>
<body>
    <form id="form1" runat="server">
Are you sure you wish to add the following information to our guestbook?<br />
<asp:Label id="Label1" runat="server" /><br /><br />
    <asp:Button ID="Confirm" runat="server" Text="Confirm" PostBackUrl="~/Guestbook/Default.aspx" />
    <asp:Button ID="Cancel" runat="server" Text="Cancel" PostBackUrl="~/Guestbook/addentry.aspx" />
</form>
</body> 
</html>

What have I done wrong here? Can anyone help?

2
Contributors
1
Reply
2
Views
7 Years
Discussion Span
Last Post by Ramesh S
1

You have mentioned SenderClass in the @Page directive in both addentry.aspx and verify.aspx.

Remove it from verify.aspx.

Also you are redirecting from addentry.aspx(from Verify() method) to verify.aspx using Response.Redirect. Therefore the following line will throw InvalidCastException error. Use Server.Transfer to avoid that error.

I have changed your code to address the above issues.

addentry.aspx

<%@ Page Language="VB" ClassName="SenderClass" %>

<script runat="server">

    ' Readonly property for first name
    Public ReadOnly Property FName() As String
        Get
            Return FirstName.Text
        End Get
    End Property

    ' Readonly property for last name
    Public ReadOnly Property LName() As String
        Get
            Return LastName.Text
        End Get
    End Property
   
    ' Readonly property for gender
    Public ReadOnly Property GenderOption() As String
        Get
            Return Gender.Text
        End Get
    End Property

    ' Readonly property for age
    Public ReadOnly Property AgeOption() As String
        Get
            Return Age.Text
        End Get
    End Property
 
    ' Readonly property for e-mail
    Public ReadOnly Property EmailOption() As String
        Get
            Return Email.Text
        End Get
    End Property
    
    'Event to transfer page control to Verify.aspx
    Sub Page_Transfer(ByVal sender As Object, ByVal e As EventArgs)
        Server.Transfer("Verify.aspx")
    End Sub
    </script>
    
<%@ Import Namespace="System.IO" %>
<html>

<script runat="server">
    
    Sub Verify(ByVal Sender As Object, _
      ByVal B As EventArgs)
        Dim GBPeople As String
        GBPeople = _
            "gbpeople.txt"
        My.Computer.FileSystem.WriteAllText(GBPeople, _
           FirstName.Text & "<br>", True)
        My.Computer.FileSystem.WriteAllText(GBPeople, _
           LastName.Text & "<br>", True)
        My.Computer.FileSystem.WriteAllText(GBPeople, _
           Gender.SelectedItem.Text & "<br>", True)
        My.Computer.FileSystem.WriteAllText(GBPeople, _
           Email.Text & "<br><br>", True)
        
        'Response.Redirect("Verify.aspx")
        Server.Transfer("Verify.aspx")
    End Sub
    </script>
    <head><title></title></head>
<body>
<h1> Sign Our Guestbook</h1>
<form id="Form1" runat="server">
First Name: <br />
<asp:TextBox id="FirstName" runat="server" /><br />
Last Name:<br />
<asp:textbox ID="LastName" runat="server" /><br />
Gender:<br />
<asp:RadioButtonList ID="Gender" runat="server">
    <asp:ListItem Selected="True">Male</asp:ListItem>
    <asp:ListItem>Female</asp:ListItem>
</asp:RadioButtonList><br />
Age:<br />
<asp:textbox id="age" runat="server"/><br />
Email Address:<br />
<asp:textbox id="Email" runat="server"/><br />
<asp:Button ID="AddMe" Text="Add Me!" runat="server" OnClick="Verify" /><br />
</form>
</body>
</html>

verify.aspx

<%@ Page Language="VB" debug="true" %>
<%@ Reference Page="addentry.aspx" %>

<script runat="server">
     
    Dim result As SenderClass

	Sub Page_load(obj as Object, e as EventArgs)
		Dim content As String

        If Not IsPostBack Then
            result = CType(Context.Handler, SenderClass)
            content = "Name: " + result.FName + "<br>" + "E-mail: " + result.EmailOption + "<br>" + "Gender: " + result.GenderOption
            Label1.Text = content
        End If
    End Sub

    Protected Sub Confirm_Click(ByVal sender As Object, ByVal e As System.EventArgs)

    End Sub
</script>

<html>
<head id="Head1" runat="server">
    <title>Untitled Page</title>
</head>
<body>
    <form id="form1" runat="server">
Are you sure you wish to add the following information to our guestbook?<br />
<asp:Label id="Label1" runat="server" /><br /><br />
    <asp:Button ID="Confirm" runat="server" Text="Confirm" PostBackUrl="~/Guestbook/Default.aspx" />
    <asp:Button ID="Cancel" runat="server" Text="Cancel" PostBackUrl="~/Guestbook/addentry.aspx" />
</form>
</body> 
</html>

Edited by Ramesh S: n/a

Votes + Comments
Exactly what I needed!
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.