Solved

Simple VB.net passing a variable from .vb to .aspx

Posted on 2008-06-17
7
252 Views
Last Modified: 2013-11-26
This is a really simple issue, but I have racked my brain on how to get these values over. I am knowledgable on asp classic but .net has me lost. All of the code I am using, or trying to use, is vb. In classic asp I could easily set a variable and say that <%test_value = 1%> then call it later by saying <%response.write test_value%>.

I basically am trying to learn how to do this simple task in VB but I am feeling stupid on why I cannot make it happen. I am trying to do the same thing but in the .vb file, and pull the value into the .aspx file.

Below is a very simple string that I want to work, which does not. I think I am attaching myself to classic and making it more difficult than it is in .net. Thanks for your help!
---.vb file---
 
Partial Class _Default
    Inherits System.Web.UI.Page
 
    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        Dim test_value = "25"
    End Sub
 
End Class
 
 
 
 
 
 
---.aspx file---
<%@ Page Language="VB" AutoEventWireup="false" CodeFile="Default.aspx.vb" Inherits="_Default" %>
 
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
 
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title>Untitled Page</title>
</head>
<body>
    <form id="form1" runat="server">
    <%Response.Write(test_value)%>
    <div>
    </div>
    </form>
</body>
</html>

Open in new window

0
Comment
Question by:drocco21
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 5
  • 2
7 Comments
 
LVL 1

Author Comment

by:drocco21
ID: 21806951
Here is the error, if it helps with this issue
Server Error in '/WebSite5' Application.
--------------------------------------------------------------------------------
 
Compilation Error 
Description: An error occurred during the compilation of a resource required to service this request. Please review the following specific error details and modify your source code appropriately. 
 
Compiler Error Message: BC30451: Name 'test_value' is not declared.
 
Source Error:
 
 
 
Line 9:  <body>
Line 10:     <form id="form1" runat="server">
Line 11:     <%Response.Write(test_value)%>
Line 12:     <div>
Line 13:     </div>
 
 
Source File: C:\Documents and Settings\dms\My Documents\Visual Studio 2008\WebSites\WebSite5\Default.aspx    Line: 11 
 
 
 
Show Detailed Compiler Output:
 
 
C:\Program Files\Microsoft Visual Studio 9.0\Common7\IDE> "C:\WINDOWS\Microsoft.NET\Framework\v3.5\vbc.exe" /t:library /utf8output /R:"C:\WINDOWS\assembly\GAC_32\System.Web\2.0.0.0__b03f5f7f11d50a3a\System.Web.dll" /R:"C:\WINDOWS\assembly\GAC_MSIL\System.Xml\2.0.0.0__b77a5c561934e089\System.Xml.dll" /R:"C:\WINDOWS\assembly\GAC_MSIL\System.Data.DataSetExtensions\3.5.0.0__b77a5c561934e089\System.Data.DataSetExtensions.dll" /R:"C:\WINDOWS\assembly\GAC_32\System.EnterpriseServices\2.0.0.0__b03f5f7f11d50a3a\System.EnterpriseServices.dll" /R:"C:\WINDOWS\assembly\GAC_MSIL\System.IdentityModel\3.0.0.0__b77a5c561934e089\System.IdentityModel.dll" /R:"C:\WINDOWS\assembly\GAC_MSIL\System.Core\3.5.0.0__b77a5c561934e089\System.Core.dll" /R:"C:\WINDOWS\assembly\GAC_MSIL\System.Drawing\2.0.0.0__b03f5f7f11d50a3a\System.Drawing.dll" /R:"C:\WINDOWS\assembly\GAC_MSIL\System.Web.Extensions\3.5.0.0__31bf3856ad364e35\System.Web.Extensions.dll" /R:"C:\WINDOWS\assembly\GAC_MSIL\System.Web.Services\2.0.0.0__b03f5f7f11d50a3a\System.Web.Services.dll" /R:"C:\WINDOWS\assembly\GAC_MSIL\System\2.0.0.0__b77a5c561934e089\System.dll" /R:"C:\WINDOWS\assembly\GAC_MSIL\System.ServiceModel\3.0.0.0__b77a5c561934e089\System.ServiceModel.dll" /R:"C:\WINDOWS\assembly\GAC_MSIL\System.Configuration\2.0.0.0__b03f5f7f11d50a3a\System.Configuration.dll" /R:"C:\WINDOWS\assembly\GAC_MSIL\System.ServiceModel.Web\3.5.0.0__31bf3856ad364e35\System.ServiceModel.Web.dll" /R:"C:\WINDOWS\assembly\GAC_MSIL\System.WorkflowServices\3.5.0.0__31bf3856ad364e35\System.WorkflowServices.dll" /R:"C:\WINDOWS\assembly\GAC_MSIL\System.Web.Mobile\2.0.0.0__b03f5f7f11d50a3a\System.Web.Mobile.dll" /R:"C:\WINDOWS\assembly\GAC_MSIL\System.Xml.Linq\3.5.0.0__b77a5c561934e089\System.Xml.Linq.dll" /R:"C:\WINDOWS\assembly\GAC_32\System.Data\2.0.0.0__b77a5c561934e089\System.Data.dll" /R:"C:\WINDOWS\assembly\GAC_MSIL\System.Runtime.Serialization\3.0.0.0__b77a5c561934e089\System.Runtime.Serialization.dll" /out:"C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\Temporary ASP.NET Files\website5\5fc5e383\9bc46f71\App_Web_3yr9qrzy.dll" /debug- /define:_MYTYPE=\"Web\" /imports:Microsoft.VisualBasic,System,System.Collections,System.Collections.Generic,System.Collections.Specialized,System.Configuration,System.Text,System.Text.RegularExpressions,System.Linq,System.Xml.Linq,System.Web,System.Web.Caching,System.Web.SessionState,System.Web.Security,System.Web.Profile,System.Web.UI,System.Web.UI.WebControls,System.Web.UI.WebControls.WebParts,System.Web.UI.HtmlControls /warnaserror- /optionInfer+  "C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\Temporary ASP.NET Files\website5\5fc5e383\9bc46f71\App_Web_3yr9qrzy.0.vb" "C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\Temporary ASP.NET Files\website5\5fc5e383\9bc46f71\App_Web_3yr9qrzy.1.vb" "C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\Temporary ASP.NET Files\website5\5fc5e383\9bc46f71\App_Web_3yr9qrzy.2.vb"
 
 
Microsoft (R) Visual Basic Compiler version 9.0.21022.8
Copyright (c) Microsoft Corporation.  All rights reserved.
 
C:\Documents and Settings\dms\My Documents\Visual Studio 2008\WebSites\WebSite5\Default.aspx(11) : error BC30451: Name 'test_value' is not declared.
 
      Response.Write(test_value)
                     ~~~~~~~~~~ 
 
 
 
 
 
 
--------------------------------------------------------------------------------
Version Information: Microsoft .NET Framework Version:2.0.50727.1433; ASP.NET Version:2.0.50727.1433 

Open in new window

0
 
LVL 1

Expert Comment

by:adrian213
ID: 21808052
On first glance I would say you haven't declared your variable properly in the code file:

Dim test_value = "25"

becomes

Dim test_value as String = "25"
0
 
LVL 1

Author Comment

by:drocco21
ID: 21809179
Hello,

I made the change above but am still receiving this error:

Server Error in '/WebSite5' Application.
--------------------------------------------------------------------------------

Compilation Error
Description: An error occurred during the compilation of a resource required to service this request. Please review the following specific error details and modify your source code appropriately.

Compiler Error Message: BC30451: Name 'test_value' is not declared.

Source Error:

 

Line 9:  <body>
Line 10:     <form id="form1" runat="server">
Line 11:     <%Response.Write(test_value)%>
Line 12:     <div>
Line 13:     </div>
 

Source File: C:\Documents and Settings\dms\My Documents\Visual Studio 2008\WebSites\WebSite5\Default.aspx    Line: 11



Show Detailed Compiler Output:


C:\Program Files\Microsoft Visual Studio 9.0\Common7\IDE> "C:\WINDOWS\Microsoft.NET\Framework\v3.5\vbc.exe" /t:library /utf8output /R:"C:\WINDOWS\assembly\GAC_32\System.Web\2.0.0.0__b03f5f7f11d50a3a\System.Web.dll" /R:"C:\WINDOWS\assembly\GAC_MSIL\System.Xml\2.0.0.0__b77a5c561934e089\System.Xml.dll" /R:"C:\WINDOWS\assembly\GAC_MSIL\System.Data.DataSetExtensions\3.5.0.0__b77a5c561934e089\System.Data.DataSetExtensions.dll" /R:"C:\WINDOWS\assembly\GAC_32\System.EnterpriseServices\2.0.0.0__b03f5f7f11d50a3a\System.EnterpriseServices.dll" /R:"C:\WINDOWS\assembly\GAC_MSIL\System.IdentityModel\3.0.0.0__b77a5c561934e089\System.IdentityModel.dll" /R:"C:\WINDOWS\assembly\GAC_MSIL\System.Core\3.5.0.0__b77a5c561934e089\System.Core.dll" /R:"C:\WINDOWS\assembly\GAC_MSIL\System.Drawing\2.0.0.0__b03f5f7f11d50a3a\System.Drawing.dll" /R:"C:\WINDOWS\assembly\GAC_MSIL\System.Web.Extensions\3.5.0.0__31bf3856ad364e35\System.Web.Extensions.dll" /R:"C:\WINDOWS\assembly\GAC_MSIL\System.Web.Services\2.0.0.0__b03f5f7f11d50a3a\System.Web.Services.dll" /R:"C:\WINDOWS\assembly\GAC_MSIL\System\2.0.0.0__b77a5c561934e089\System.dll" /R:"C:\WINDOWS\assembly\GAC_MSIL\System.ServiceModel\3.0.0.0__b77a5c561934e089\System.ServiceModel.dll" /R:"C:\WINDOWS\assembly\GAC_MSIL\System.Configuration\2.0.0.0__b03f5f7f11d50a3a\System.Configuration.dll" /R:"C:\WINDOWS\assembly\GAC_MSIL\System.ServiceModel.Web\3.5.0.0__31bf3856ad364e35\System.ServiceModel.Web.dll" /R:"C:\WINDOWS\assembly\GAC_MSIL\System.WorkflowServices\3.5.0.0__31bf3856ad364e35\System.WorkflowServices.dll" /R:"C:\WINDOWS\assembly\GAC_MSIL\System.Web.Mobile\2.0.0.0__b03f5f7f11d50a3a\System.Web.Mobile.dll" /R:"C:\WINDOWS\assembly\GAC_MSIL\System.Xml.Linq\3.5.0.0__b77a5c561934e089\System.Xml.Linq.dll" /R:"C:\WINDOWS\assembly\GAC_32\System.Data\2.0.0.0__b77a5c561934e089\System.Data.dll" /R:"C:\WINDOWS\assembly\GAC_MSIL\System.Runtime.Serialization\3.0.0.0__b77a5c561934e089\System.Runtime.Serialization.dll" /out:"C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\Temporary ASP.NET Files\website5\5fc5e383\9bc46f71\App_Web_dldwpdsi.dll" /debug- /define:_MYTYPE=\"Web\" /imports:Microsoft.VisualBasic,System,System.Collections,System.Collections.Generic,System.Collections.Specialized,System.Configuration,System.Text,System.Text.RegularExpressions,System.Linq,System.Xml.Linq,System.Web,System.Web.Caching,System.Web.SessionState,System.Web.Security,System.Web.Profile,System.Web.UI,System.Web.UI.WebControls,System.Web.UI.WebControls.WebParts,System.Web.UI.HtmlControls /warnaserror- /optionInfer+  "C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\Temporary ASP.NET Files\website5\5fc5e383\9bc46f71\App_Web_dldwpdsi.0.vb" "C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\Temporary ASP.NET Files\website5\5fc5e383\9bc46f71\App_Web_dldwpdsi.1.vb" "C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\Temporary ASP.NET Files\website5\5fc5e383\9bc46f71\App_Web_dldwpdsi.2.vb"


Microsoft (R) Visual Basic Compiler version 9.0.21022.8
Copyright (c) Microsoft Corporation.  All rights reserved.

C:\Documents and Settings\dms\My Documents\Visual Studio 2008\WebSites\WebSite5\Default.aspx(11) : error BC30451: Name 'test_value' is not declared.

      Response.Write(test_value)
                     ~~~~~~~~~~

 




--------------------------------------------------------------------------------
Version Information: Microsoft .NET Framework Version:2.0.50727.1433; ASP.NET Version:2.0.50727.1433
---.vb file---
Partial Class _Default
    Inherits System.Web.UI.Page
 
    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        Dim test_value As String = "25"
    End Sub
 
End Class
 
 
---.aspx file---
<%@ Page Language="VB" AutoEventWireup="false" CodeFile="Default.aspx.vb" Inherits="_Default" %>
 
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
 
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title>Untitled Page</title>
</head>
<body>
    <form id="form1" runat="server">
    <%Response.Write(test_value)%>
    <div>
    </div>
    </form>
</body>
</html>

Open in new window

0
Creating Instructional Tutorials  

For Any Use & On Any Platform

Contextual Guidance at the moment of need helps your employees/users adopt software o& achieve even the most complex tasks instantly. Boost knowledge retention, software adoption & employee engagement with easy solution.

 
LVL 1

Accepted Solution

by:
adrian213 earned 500 total points
ID: 21810933
Apologies, I should have looked more thoroughly.

I would have Response.Write(test_value) in the code behind i.e.

---.vb file---
Partial Class _Default
    Inherits System.Web.UI.Page
 
    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        Dim test_value As Integer = 25
        Response.Write(test_value)
    End Sub
 
End Class


And remove <% %> from the aspx file.

Take a look here for some help to get you up to speed http://www.asp.net/learn
0
 
LVL 1

Author Comment

by:drocco21
ID: 21811841
ahh, I am hanging on to classic asp way to much i see. I am not used to the work being done in an external file. Thanks, and I know this was probably simple for you, but it has waken me up and helped me.

Sincerely,

Dave
0
 
LVL 1

Author Closing Comment

by:drocco21
ID: 31468122
Thanks!
0
 
LVL 1

Author Comment

by:drocco21
ID: 21812077
Here is another question I have that may be easy for you to assist with:
http://www.experts-exchange.com/Microsoft/Development/.NET/Visual_Studio_2008/Q_23494871.html

Thanks again
0

Featured Post

Why You Need a DevOps Toolchain

IT needs to deliver services with more agility and velocity. IT must roll out application features and innovations faster to keep up with customer demands, which is where a DevOps toolchain steps in. View the infographic to see why you need a DevOps toolchain.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

This document covers how to connect to SQL Server and browse its contents.  It is meant for those new to Visual Studio and/or working with Microsoft SQL Server.  It is not a guide to building SQL Server database connections in your code.  This is mo…
Creating an analog clock UserControl seems fairly straight forward.  It is, after all, essentially just a circle with several lines in it!  Two common approaches for rendering an analog clock typically involve either manually calculating points with…
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…
How to Install VMware Tools in Red Hat Enterprise Linux 6.4 (RHEL 6.4) Step-by-Step Tutorial

739 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question