PDA

View Full Version : ASP.net Variable Question


jgallen23
09-20-2004, 06:51 PM
I have a variable set in page load and in my page I have a hyperlink that needs that variable. How do I insert that in asp.net? I know in classic asp it was just <%=

Here's the example

sub page_load
dim text as integer = 4
end sub

<a href="blah.aspx?go=<%= text %> >

I know that doesn't work because it's the classic syntax, can anybody help me out with an asp.net compatible version?

allida77
09-21-2004, 06:26 AM
In asp.net there are 2:
<%= var %>
<%# property %>

The first is classic asp and is a runtime shortcut for Response.Write()
The second is the new way and is evaluated when the Databind() method is called.

Are you using code behind? The asp.net way would be to declare a "text" property on the codebehind page:


page1.aspx.vb
Private _text Integer

Public Readonly Property Text as Integer
return _text
End Property

Sub Page_Load(....)
_text=33
Databind()
End Sub

page1.aspx

<a href="blah.aspx?go=<%# Text %> >



If you are not using code behind then you can just put that in the code section of your aspx page. You may want to look into the Page.Databind method in the .net sdk to get some more info.

gwendaal
09-21-2004, 03:14 PM
but asp net IS codebehind then the use of <% is a old and poor method even if it works