Solved

Display variable on asp.net page

Posted on 2004-09-22
16
10,280 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:imsolost
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
 
LVL 7

Expert Comment

by:imsolost
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:imsolost
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
Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

 

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:
imsolost earned 50 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:imsolost
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 25 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

Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

Join & Write a Comment

Sometimes in DotNetNuke module development you want to swap controls within the same module definition.  In doing this DNN (somewhat annoyingly) swaps the Skin and Container definitions to the default admin selections.  To get around this you need t…
A quick way to get a menu to work on our website, is using the Menu control and assign it to a web.sitemap using SiteMapDataSource. Example of web.sitemap file: (CODE) Sample code to add to the page menu: (CODE) Running the application, we wi…
It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.
You have products, that come in variants and want to set different prices for them? Watch this micro tutorial that describes how to configure prices for Magento super attributes. Assigning simple products to configurable: We assigned simple products…

760 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

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now