471,066 Members | 1,294 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,066 software developers and data experts.

Sharing variables between <% %> and a function

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.

Apr 5 '06 #1
8 1406
declare it at class level either as protected or public

--
Robbe Morris - 2004-2006 Microsoft MVP C#
Earn money answering .NET questions
http://www.eggheadcafe.com/forums/merit.asp

<an***********@yahoo.com> wrote in message
news:11**********************@i40g2000cwc.googlegr oups.com...
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.

Apr 5 '06 #2
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.

Robbe Morris [C# MVP] wrote:
declare it at class level either as protected or public

--
Robbe Morris - 2004-2006 Microsoft MVP C#
Earn money answering .NET questions
http://www.eggheadcafe.com/forums/merit.asp

<an***********@yahoo.com> wrote in message
news:11**********************@i40g2000cwc.googlegr oups.com...
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.


Apr 5 '06 #3
Just like you did in your previous post.

--
Robbe Morris - 2004-2006 Microsoft MVP C#
Earn money answering .NET questions
http://www.eggheadcafe.com/forums/merit.asp

<an***********@yahoo.com> wrote in message
news:11**********************@g10g2000cwb.googlegr oups.com...
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.

Robbe Morris [C# MVP] wrote:
declare it at class level either as protected or public

--
Robbe Morris - 2004-2006 Microsoft MVP C#
Earn money answering .NET questions
http://www.eggheadcafe.com/forums/merit.asp

<an***********@yahoo.com> wrote in message
news:11**********************@i40g2000cwc.googlegr oups.com...
> 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.
>

Apr 5 '06 #4
I guess you don't wanna bother to give a more enlightening example.
Thanks anyway.

Apr 5 '06 #5
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

<an***********@yahoo.com> wrote in message
news:11*********************@u72g2000cwu.googlegro ups.com...
I guess you don't wanna bother to give a more enlightening example.
Thanks anyway.

Apr 5 '06 #6
<%@ 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>

<an***********@yahoo.com> wrote in message
news:11**********************@i40g2000cwc.googlegr oups.com...
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.

Apr 5 '06 #7
Thanks a lot. This code snippet is great! I got the idea now.
Ken Cox - Microsoft MVP wrote:
<%@ 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>

<an***********@yahoo.com> wrote in message
news:11**********************@i40g2000cwc.googlegr oups.com...
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.


Apr 5 '06 #8
This was your code...

<param name="fileName" value="<%= myString %>">
--
Robbe Morris - 2004-2006 Microsoft MVP C#
Earn money answering .NET questions
http://www.eggheadcafe.com/forums/merit.asp

<an***********@yahoo.com> wrote in message
news:11********************@u72g2000cwu.googlegrou ps.com...
Thanks a lot. This code snippet is great! I got the idea now.
Ken Cox - Microsoft MVP wrote:
<%@ 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>

<an***********@yahoo.com> wrote in message
news:11**********************@i40g2000cwc.googlegr oups.com...
> 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.
>

Apr 5 '06 #9

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

1 post views Thread by Christian Schmidbauer | last post: by
9 posts views Thread by Rolf Kemper | last post: by
2 posts views Thread by Donald Firesmith | last post: by
4 posts views Thread by higabe | last post: by
11 posts views Thread by Les Paul | last post: by
10 posts views Thread by EOZyo | last post: by
14 posts views Thread by Motion Musso aka: Sathia | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.