how access class variable in .net

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • navics044
    New Member
    • Nov 2007
    • 1

    how access class variable in .net

    i crated calss as data.vb in vb.net and i am declaring variable public a as string
    and a="ABC" and i want to use this variable value when form loaded and disply that text in lable how can i do
  • aaronsandoval
    New Member
    • Nov 2007
    • 13

    #2
    Originally posted by navics044
    i crated calss as data.vb in vb.net and i am declaring variable public a as string
    and a="ABC" and i want to use this variable value when form loaded and disply that text in lable how can i do
    Okay, you created a class as "data.vb" and in that class you set a public string equal to "ABC", within your code behind page for example "Default.aspx.v b" you would like to get this value and put it in a label control on page load.

    ASP.NET VB.NET HTML CODE PAGE (Default.aspx)
    [HTML]
    <%@ Page Language="VB" AutoEventWireup ="false" CodeFile="Defau lt.aspx.vb" Inherits="_Defa ult" %>

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dt d">

    <html xmlns="http://www.w3.org/1999/xhtml" >

    <head runat="server">

    <title>VB.NET Class Example</title>

    </head>

    <body>

    <form id="form1" runat="server">

    <div>

    <asp:Label ID="Label1" runat="server" Text=""></asp:Label>

    </div>

    </form>

    </body>

    </html>

    [/HTML]

    ASP.NET VB.NET CODE BEHIND PAGE (Default.aspx.v b)
    [CODE=vb]
    Partial Class _Default

    Inherits System.Web.UI.P age

    Protected Overrides Sub OnInit(ByVal e As System.EventArg s)

    Dim mdc As New myDataClass()

    ' ADD CLASS DATA TO LABEL

    Label1.Text = mdc.a.ToString

    End Sub

    End Class

    [/CODE]

    ASP.NET VB.NET CLASS PAGE in App_Code folder (myDataClass.vb )
    [CODE=vb]
    Imports Microsoft.Visua lBasic

    Public Class myDataClass

    Public a As String = "ABC"

    End Class

    [/CODE]

    I hope this will helps you, please let me know if any further explination is needed.

    - Aaron Sandoval
    "remember: There's a thin line between good | great..."

    Comment

    Working...