473,385 Members | 1,958 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

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

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

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
Nov 19 '05 #1
5 1404
"Johnb41" <or****@informatik.com> wrote in message
news:0c****************************@phx.gbl...
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
Nov 19 '05 #2
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

Nov 19 '05 #3
"johnb41" <or****@informatik.com> wrote in message
news:11**********************@z14g2000cwz.googlegr oups.com...
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
Nov 19 '05 #4
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

Nov 19 '05 #5
"johnb41" <or****@informatik.com> wrote in message
news:11**********************@c13g2000cwb.googlegr oups.com...
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
Nov 19 '05 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: RSB | last post by:
Hi Every one, Having tuff time to make this work .. i want to have a button and on my form say Delete button. So once i click on it i want to confirm "Are you sure?" on the Client Side and if...
1
by: John Smith | last post by:
I created a dataTable that returns a value from a stored procedure. How would I bind that results of a query to an <asp:label>? Thank you!
6
by: Andreas Klemt | last post by:
Hello, when I use <asp:label font-size="16px" text="Hello World" runat="server" /> and run FireFox Browser the output of "Hello World" is not in Size 16px. The size will be ignored and I can...
3
by: nick | last post by:
Is possible for server side code to access the text of <asp:label> changed by client side javascript code?
2
by: xzzy | last post by:
I need to update the .Text of a label until the user logs out. but get this error: Error: Method name expected I have listed the code below and the offending line of code is delimited by ...
4
by: mark.norgate | last post by:
Why oh why does my <asp:labelrevert to its initial value, having been changed programmatically, when I click a button in a user control I have added dynamically to the page? It's EnableViewState is...
7
by: Smokey Grindle | last post by:
How can you correctly use the <labelelement in asp.net? does the label custom control corelate to this tag correctly in the same way in that if you click it it will select the tied element? thanks
8
by: gelligokul | last post by:
Hello frens i want to retrieve <asp:label> value from the code behind in c# can any one help me...
3
by: Homer J. Simpson | last post by:
I have the following stored procedure: ALTER PROCEDURE . AS BEGIN SET NOCOUNT ON; SELECT COUNT(*) FROM QUICKNOTES END ....and the following data source in my .aspx file:
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

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.