Results 1 to 7 of 7

Thread: Newbie needs help on Undeclared Web Field

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Nov 2016
    Posts
    125

    Newbie needs help on Undeclared Web Field

    My first venture into Web Projects, a completely coded class example project is not working. The instructions call for just typing “HiddenField – DiscountHiddenField” in a table cell. I am now receiving DiscountHiddenField not declared.

    Is there a missing instruction that I need? TIA jp

    Code:
                ' Save the discount total in a label
                DiscountHiddenField.Value = DiscountTotalDecimal.ToString()
    
    
    
            ' Check for existing value for the discount total.
            With DiscountHiddenField
                If IsPostBack And .Value <> "" Then
                    DiscountTotalDecimal = Decimal.Parse(.Value)
                End If
            End With

    Severity Code Description Project File Line Suppression State
    Error BC30451 'DiscountHiddenField' is not declared. It may be inaccessible due to its protection level. Chapter 9 HandsOn d:\documents\visual studio 2017\Projects for the Web\Chapter 9 HandsOn\Chapter 9 HandsOn\My Project\Default.aspx.vb 38 Active
    Error BC30451 'DiscountHiddenField' is not declared. It may be inaccessible due to its protection level. Chapter 9 HandsOn d:\documents\visual studio 2017\Projects for the Web\Chapter 9 HandsOn\Chapter 9 HandsOn\My Project\Default.aspx.vb 66 Active

  2. #2

    Thread Starter
    Lively Member
    Join Date
    Nov 2016
    Posts
    125

    Re: Newbie needs help on Undeclared Web Field

    Do I need to add declaration to make my example code work? TIA JP

    Code:
    'Declaration
    <ControlValuePropertyAttribute("Value")> _
    Public Class HiddenField _
    	Inherits Control _
    	Implements IPostBackDataHandler
    End Class
    Example project:
    Code:
    ' Project:          CH 9 HandsOn
    ' Programmer:       Bradley/Millspaugh 
    ' Date:             Jun 2010
    ' Description:      A Web site to calculate the extended price for books sold,
    '                   at discount, and the discounted amount. Calculates and displaysthe total discounts.
    '                   Uses validator controls for input validation.
    ' Folder            Ch09HansOn                  
    ' Exercise:         From "Programming in Visual Basic 2010" by Julia C. Bradley & Anita C. Millspaugh
    '                   On page 286 - 393.
    '
    ' Partial class name and inherits problem? _Default vs _Default_aspx yielded undeclared variable errors!
    Partial Class _Default
        Inherits System.Web.UI.Page
    
        Private DiscountTotalDecimal As Decimal
        Const DISCOUNT_RATE_DECIMAL As Decimal = 0.15D
    
        Protected Sub SubmitButton_Click(sender As Object, e As EventArgs) Handles SubmitButton.Click
            ' Calculate values for sale.
            Dim QuantityInteger As Integer
            Dim PriceDecimal, EtendedPriceDecimal As Decimal
            Dim DiscountDecimal, DiscountPriceDecimal As Decimal
            ErrorMessageLabel1.Text = String.Empty
            Try
                ' Convert input values to numeric variables.
                QuantityInteger = Integer.Parse(QuantityTextBox.Text)
                PriceDecimal = Decimal.Parse(PriceTextBox.Text)
    
                ' Calculate values for sale.
                EtendedPriceDecimal = QuantityInteger * PriceDecimal
                DiscountDecimal = EtendedPriceDecimal * DISCOUNT_RATE_DECIMAL
                DiscountPriceDecimal = EtendedPriceDecimal - DiscountDecimal
    
                ' Add to the discount total
                DiscountTotalDecimal += DiscountPriceDecimal
    
                ' Save the discount total in a label
                DiscountHiddenField.Value = DiscountTotalDecimal.ToString()
    
                ' Format and display answers.
                ExtendedPriceTextBox.Text = EtendedPriceDecimal.ToString("C")
                DiscountTextBox.Text = DiscountDecimal.ToString("N")
                DiscountedPriceTextBox.Text = DiscountPriceDecimal.ToString("C")
    
    
            Catch ex As Exception
                ErrorMessageLabel1.Text = "Unable to calculate. Check for numeric values."
            End Try
    
        End Sub
    
        Protected Sub ClearButton_Click(sender As Object, e As EventArgs) Handles ClearButton.Click
            ' Clear previous amounts from the page.
            QuantityTextBox.Text = ""
            TitleTextBox.Text = ""
            PriceTextBox.Text = ""
            ExtendedPriceTextBox.Text = ""
            DiscountTextBox.Text = ""
            '    DiscountlHiddenField.Text = ""
            DiscountTotalLabel.Text = ""
            ErrorMessageLabel1.Text = ""
        End Sub
    
        Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
            ' Check for existing value for the discount total.
            With DiscountHiddenField
                If IsPostBack And .Value <> "" Then
                    DiscountTotalDecimal = Decimal.Parse(.Value)
                End If
            End With
    
        End Sub
        Private Sub SummaryButton_Click(sender As Object, e As EventArgs) Handles SummaryButton.Click
            ' Displaythe total discount.
    
            ' DiscountTotalLabel.Text = "Total Discounts: $" & DiscountTotalHiddenField.Value
            DiscountTotalLabel.Text = "Total Discounts: $" & DiscountTotalDecimal.ToString
    
        End Sub
    
    End Class

  3. #3
    Frenzied Member KGComputers's Avatar
    Join Date
    Dec 2005
    Location
    Cebu, PH
    Posts
    2,020

    Re: Newbie needs help on Undeclared Web Field

    Did you add a hidden field control in your aspx markup same as the textbox and label controls?
    CodeBank: VB.NET & C#.NET | ASP.NET
    Programming: C# | VB.NET
    Blogs: Personal | Programming
    Projects: GitHub | jsFiddle
    ___________________________________________________________________________________

    Rating someone's post is a way of saying Thanks...

  4. #4

    Thread Starter
    Lively Member
    Join Date
    Nov 2016
    Posts
    125

    Re: Newbie needs help on Undeclared Web Field

    Thanks for your response. There were no instructions for adding a hidden field control in my aspx markup same as the textbox and label controls. I do not know enough to do so!
    aspx markup? Would that entail using 'Markup Fragment' tool, if so how do you use it? TIA JP

  5. #5
    Smooth Moperator techgnome's Avatar
    Join Date
    May 2002
    Posts
    34,537

    Re: Newbie needs help on Undeclared Web Field

    Probably not... you would open the aspx page which contains all the weby stuff... the HTML and other front-end elements. That's where you need to add the field to. Then mark it as hidden. Once you've done that, you should then be able to access it from the .codebehind.vb file (where your code should be) with out any further issues.

    -tg
    * I don't respond to private (PM) requests for help. It's not conducive to the general learning of others.*
    * I also don't respond to friend requests. Save a few bits and don't bother. I'll just end up rejecting anyways.*
    * How to get EFFECTIVE help: The Hitchhiker's Guide to Getting Help at VBF - Removing eels from your hovercraft *
    * How to Use Parameters * Create Disconnected ADO Recordset Clones * Set your VB6 ActiveX Compatibility * Get rid of those pesky VB Line Numbers * I swear I saved my data, where'd it run off to??? *

  6. #6

    Thread Starter
    Lively Member
    Join Date
    Nov 2016
    Posts
    125

    Re: Newbie needs help on Undeclared Web Field

    Lacking experience and no guidance from the textbook, I simply typed “HiddenField – DiscountHiddenField” in a table cell. I now see a tool 'Hiddenfield' which removed the previous errors, and now I have an issue with the several usages of 'Value':

    Severity Code Description Project File Line Suppression State
    Error BC30456 'Value' is not a member of 'HtmlForm'. Chapter 9 HandsOn d:\documents\visual studio 2017\Projects for the Web\Chapter 9 HandsOn\Chapter 9 HandsOn\My Project\Default.aspx.vb 40 Active

    Progress is slow but moving! TIA JP

  7. #7

    Thread Starter
    Lively Member
    Join Date
    Nov 2016
    Posts
    125

    Re: Newbie needs help on Undeclared Web Field

    I suspect part of my problem is that the textbook was written for VS 2010 and I am using VS community 2017.

    Having looked at internet sample, it would appear that 'value' needs to be built into the source code - something I know nothing about. JP
    Code:
    <%@ Page Language="vb" AutoEventWireup="false" CodeBehind="Default.aspx.vb" Inherits="Chapter_9_HandsOn._Default" %>
    
    <!DOCTYPE html>
    
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head runat="server">
        <title></title>

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width