[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

Display variable on asp.net page

Posted on 2004-09-22
16
Medium Priority
?
10,328 Views
Last Modified: 2011-10-03
I am trying to show text on the webpage if the value of edit = 1 but i get an error:

Name 'edit' is not declared.

with this code:

<% If edit = 1 Then %>
EDIT MODE
<% End If  %>

from a previous question, from ImSoLost

Why not do this server side?  something like this

dim edit as integer

If Edit = 1 then
     label1.text = "whatever you want to say on the page"
Else
    label1.text = "Whatever you say for this condition"
End If

0
Comment
Question by:crich
  • 6
  • 5
  • 5
16 Comments
 
LVL 4

Expert Comment

by:Andre412
ID: 12122648
you must instantiate all variables on the form

close to the top you should have something like

<% dim edit as integer or boolean or whatever %>

later in the form you need to assign a value to it

<% if case1 then edit = value else edit = othervalue %>

then again perform a test on it for your text

<% if edit = 1 then %>
some text
<%end if%>

alternatively

<% if edit = 1 then response.wrtie("Some text") %>
0
 
LVL 7

Expert Comment

by:Fred Goodwin
ID: 12122811
Why not do this server side?  something like this

dim edit as integer

If Edit = 1 then
     label1.text = "whatever you want to say on the page"
Else
    label1.text = "Whatever you say for this condition"
End If
0
 
LVL 4

Expert Comment

by:Andre412
ID: 12123100
because he will then be limited on formating, he wont be able to dynamically change font styles colours etc and what if his page is dynamically built anyway with no fised label position or size?
0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
LVL 7

Expert Comment

by:Fred Goodwin
ID: 12123148
you can still change all of that with server side code.  It may not be the way he is used to doing it but it can still be done just the same.  The question was really directed at crich though.  
0
 

Author Comment

by:crich
ID: 12123270
I get the following error:

Name 'edit' is not declared

with this code:

Sub Page_Load (s as object, e as eventargs)
        Dim objChkUsername As String = Session("chkusername")
 
        If IsDBNull(objChkUsername)  Or objChkUsername=" "  Then
              edit = 0
        Else
              edit = 1
        End If
            
    End Sub
0
 
LVL 7

Expert Comment

by:Fred Goodwin
ID: 12123336
change it to this

Sub Page_Load (s as object, e as eventargs)
        Dim objChkUsername As String = Session("chkusername")
        Dim Edit as Integer

        If IsDBNull(objChkUsername)  Or objChkUsername=" "  Then
              edit = 0
        Else
              edit = 1
        End If
         
    End Sub
0
 

Author Comment

by:crich
ID: 12123339
this is how i am trying to use the edit variable and where the code says the error is:

<% if edit = 0 then %> EDIT <% end if %>
0
 

Author Comment

by:crich
ID: 12123387
Sorry - yes i have also tried :

Sub Page_Load (s as object, e as eventargs)
        Dim edit as Integer
        Dim objChkUsername As String = Session("chkusername")
 
        If IsDBNull(objChkUsername) Or objChkUsername=" "  Then
              edit = 0
        Else
              edit = 1
        End If
            
    End Sub
0
 

Author Comment

by:crich
ID: 12123403
I also tried doing this the server side way you suggest but didn't know how to use the label1.text tag on the webpage without having to put it in a text box.
0
 
LVL 7

Accepted Solution

by:
Fred Goodwin earned 200 total points
ID: 12123505
in your html just do this

<asp:label runat="server" id="label1" />

Now when in your code you say
label1.text="Whatever you want to say"

The line "Whatever you want to say" will show up wherever the asp:Label control is on the page
0
 
LVL 4

Expert Comment

by:Andre412
ID: 12123613
what is this edit variable used for and where are you setting its value?
0
 

Author Comment

by:crich
ID: 12123636
Ok. The text now appears on the page but doesn't seem to be responding to the conditios that determine whether it should be shown. i have a log out script:

<script runat="server">
Sub Page_Load(s as Object, e as eventArgs)
Dim objChkUsername As String = Session("chkusername")
If Not IsDBNull(objChkUsername)  Or objChkUsername<>" "  Then
Session("chkusername")= ""
Response.Redirect("index.aspx")
Else
Response.Redirect("index.aspx")
End If
End Sub
</script>

When this is run my session variable should be empty so why does it seem like edit still equals 1??
0
 
LVL 7

Expert Comment

by:Fred Goodwin
ID: 12123776
if you want to ensure that the session is empty you can do a
session.abandon

Did you hard code Edit = 1 somewhere else?
0
 
LVL 4

Expert Comment

by:Andre412
ID: 12123841
it is prob better code practice to remove the session object then set it to an empty string, you then don't need to declare set or check a second string value, but why are you redirecting to login regardless of the result of the if statement

Sub Page_Load(s as Object, e as eventArgs)
        'line below is all on one line
        If Not IsNothing(Session("chkusername")) Then objChkUsername = Session("chkusername") Else Session.Remove("chkusername")
Response.Redirect("index.aspx")
End Sub
0
 
LVL 4

Assisted Solution

by:Andre412
Andre412 earned 100 total points
ID: 12123861
forgot to add the following declaration

Dim objChkUsername As String = "NoUser"
0
 

Author Comment

by:crich
ID: 12123965
Thank you for the answers. I split the points as the combination of working through all the possibilites has lead to the right solution.

Thanks,
Richard
0

Featured Post

Vote for the Most Valuable Expert

It’s time to recognize experts that go above and beyond with helpful solutions and engagement on site. Choose from the top experts in the Hall of Fame or on the right rail of your favorite topic page. Look for the blue “Nominate” button on their profile to vote.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
The article shows the basic steps of integrating an HTML theme template into an ASP.NET MVC project
This Micro Tutorial will teach you how to add a cinematic look to any film or video out there. There are very few simple steps that you will follow to do so. This will be demonstrated using Adobe Premiere Pro CS6.
Despite its rising prevalence in the business world, "the cloud" is still misunderstood. Some companies still believe common misconceptions about lack of security in cloud solutions and many misuses of cloud storage options still occur every day. …
Suggested Courses

834 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question