<asp:label> with the same text value....

J

Johnb41

I want an "order number" to be displayed more than once
on my page.

<script language="vb" runat="server">
...
dim ordernumber as string = "123456"
page.databind()
...
</script>

<p>text text text</p>
<asp:label runat="server" text='<%# ordernumber %>' />
<p>more text more text</p>
<asp:label runat="server" text='<%# ordernumber %>' />
<p>The order number could be displayed in other places on
the page as well.</p>

My error is "Name 'ordernumber' is not declared"

Is this the right way to do this? Some help would be
greatly appreciated!

Thanks,
John
 
J

John Saunders

Johnb41 said:
I want an "order number" to be displayed more than once
on my page.

<script language="vb" runat="server">
...
dim ordernumber as string = "123456"
page.databind()
...
</script>

<p>text text text</p>
<asp:label runat="server" text='<%# ordernumber %>' />
<p>more text more text</p>
<asp:label runat="server" text='<%# ordernumber %>' />
<p>The order number could be displayed in other places on
the page as well.</p>

My error is "Name 'ordernumber' is not declared"

Is this the right way to do this? Some help would be
greatly appreciated!

Where did you put that script? What is the scope of ordernumber? It's the
subroutine that "dim" line is in, and doesn't include the entire page.

You need to declare such a thing at page level.

Since I never use server-side script in a .aspx file, I can't tell you how
to do this that way. If you were using codebehind, I'd tell you to put:

Protected ordernumber As String = "123456"

outside of any subroutine.


John Saunders
 
J

johnb41

Thanks, it works when i declare the variable outside any sub routine.
However, in my real page, the order number is grabbed from a hashtable
item. I ran into a more serious problem that i wasn't able to fix...
but i found a sufficient workaround.

Inside my sub routine, i set the hashtable item (the order number) to
be a session variable:

session("ordernumber") = hashtable("OrderNumber")

Then for the label, i did:

<asp:label runat="server" text='<%# session("OrderNumber") %>' />

Probably not the best solution, but it's good enough for me.
Thanks again for your help!

John
 
J

John Saunders

johnb41 said:
Thanks, it works when i declare the variable outside any sub routine.
However, in my real page, the order number is grabbed from a hashtable
item. I ran into a more serious problem that i wasn't able to fix...
but i found a sufficient workaround.

Inside my sub routine, i set the hashtable item (the order number) to
be a session variable:

session("ordernumber") = hashtable("OrderNumber")

Then for the label, i did:

<asp:label runat="server" text='<%# session("OrderNumber") %>' />

Probably not the best solution, but it's good enough for me.

Why not just declare the Hashtable outside of any sub, then reference it in
the databinding expression like you're now doing with session?

John Saunders
 
J

johnb41

That was the problem that i wasn't able to figure out.

I added this line outside all sub routines:

Dim Hashtable_OrderInfo as new Hashtable(Ctype(Session("OrderInfo"),
Hashtable))

A little history: The previous page added items to the hash table. To
bring this info to the next page, i put the hashtable info into a
session variable. Then on the next page i converted the session
variable back into a hashtable (using the line of code above).

The code works perfectly fine inside of a sub routine, but when it's
outside of a routine, i get an error saying that i cannot use a session
variable. The error gives me advice on how to fix it, but it still
gives me the same error. I ran across this problem a couple days
ago... after a full day of frustration, i gave up. So when this error
came up today, I just didn't want to deal with it!

John
 
J

John Saunders

johnb41 said:
That was the problem that i wasn't able to figure out.

I added this line outside all sub routines:

Dim Hashtable_OrderInfo as new Hashtable(Ctype(Session("OrderInfo"),
Hashtable))

A little history: The previous page added items to the hash table. To
bring this info to the next page, i put the hashtable info into a
session variable. Then on the next page i converted the session
variable back into a hashtable (using the line of code above).

The code works perfectly fine inside of a sub routine, but when it's
outside of a routine, i get an error saying that i cannot use a session
variable.

Could you please post the error message?

Also, try doing the above step by step so you can see what step it failed
at. Try changing the hashtable to:

Protected Hashtable_OrderInfo As Hashtable()

and then, at the end of OnInit (or Page_Init, if that's how VB.NET does
things):

Dim ht As Hashtable = DirectCast(Session("OrderInfo"), Hashtable)
Hashtable_OrderInfo = New Hashtable(ht)

(use DirectCast when you know what the source type is, and you don't need it
converted to another type - you just need the actual source type
acknowledged)

John Saunders
 

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,755
Messages
2,569,537
Members
45,020
Latest member
GenesisGai

Latest Threads

Top