Sharing variables between <% %> and a function

A

antonyliu2002

Hi, gurus:

For VB.NET, if I have a variable myString somewhere inside <% and %>
in a page called mypage.aspx like so:

<%
'.... some code here
myString = "Junkie.txt"
'.... some other code here
%>

My client side code will use 'myString' like this:

<param name="fileName" value="<%= myString %>">

Now can I also have a function in the same page and have the function
use myString? In other words, can I have something like below in
mypage.aspx?

Sub mySub()
lblMessage.Text = myString
End Sub

Assuming that lblMessage is a Label control declared in mypage.aspx.

When I was trying to do this, the compiler says that 'myString' is not
declared.

Did I make the idea clear? How to implement it? Thanks.
 
A

antonyliu2002

Hey, Robbe,

Thanks for your hint. But I am new to VB.NET. I used to do Java.

Would you mind giving me an example, such as below?

Class MyClass
Dim Public myString As String
blah blah blah
End Class

And then how to use it? My mind is chaotic about this stuff.
 
A

antonyliu2002

I guess you don't wanna bother to give a more enlightening example.
Thanks anyway.
 
C

clintonG

I think part of the problem is the appearnace of the question to be so lame
as a "former Java developer" you should just write the one line of code and
see if it works yourself.

<%= Clinton Gallagher
 
K

Ken Cox - Microsoft MVP

<%@ Page Language="VB" %>

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

<script runat="server">
Public myString
Sub mySub()
lblMessage.Text = myString
End Sub
</script>

<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>Untitled Page</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<%
myString = "Junkie.txt"
mySub()
%>
<param name="fileName" value="<%= myString %>">
<asp:label id="lblMessage" runat="server" text="Label"></asp:label>
</div>
</form>
</body>
</html>
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,579
Members
45,053
Latest member
BrodieSola

Latest Threads

Top