SitePoint Sponsor

User Tag List

Results 1 to 2 of 2
  1. #1
    SitePoint Zealot
    Join Date
    Sep 2010
    Posts
    131
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Reference an object

    Trying to write a program in ASP.net using Visual Basic.

    Getting stuck on the objects.

    The tool tip says: "Reference to a non-shared member requires an object reference".

    How do I reference an object of a TextBox1 and DropDownList1 also Button1 need a withevents so I can run my vb code?

    Code:
    <%@ Page Title="Home Page" Language="vb" MasterPageFile="~/Site.Master" AutoEventWireup="false"
        CodeBehind="Default.aspx.vb" Inherits="WebApplication1._Default" %>
    
    <asp:Content ID="HeaderContent" runat="server" ContentPlaceHolderID="HeadContent">
    </asp:Content>
    <asp:Content ID="BodyContent" runat="server" ContentPlaceHolderID="MainContent">
        <asp:TextBox ID="TextBox1" runat="server">07</asp:TextBox>
        <asp:DropDownList ID="DropDownList1" runat="server">
                <asp:ListItem>AM</asp:ListItem>
                <asp:ListItem>PM</asp:ListItem>
        </asp:DropDownList>
        <asp:Button ID="Button1" runat="server" Text="Button1" /></td>
    </asp:Content>
    <script runat="server">
            Public Class Form1
                Private Sub Button1_Click(sender As System.Object, e As System.EventArgs) Handles Button1.Click
                     Dim a1, a2 as Double
                     a1 = Textbox1.Text
                     Select Case DropDownList1.Text
                          Case "AM"
                              a2 = 0
                          Case "PM"
                              a2 = 1
                    End Select
              End Sub
          End Class
    </script>

  2. #2
    SitePoint Mentor NightStalker-DNS's Avatar
    Join Date
    Jul 2004
    Location
    Cape Town, South Africa
    Posts
    2,880
    Mentioned
    48 Post(s)
    Tagged
    0 Thread(s)
    Change <asp:TextBox ID="TextBox1" runat="server">07</asp:TextBox>

    to

    <asp:TextBox ID="TextBox1" runat="server" Text="07"></asp:TextBox>

    You should be able to access your dropdown like that, but you do not use .Text. You want to use DropDownList1.SelectedValue(); or DropDownList1.SelectedText();


Bookmarks

Posting Permissions

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