tags:

views:

51

answers:

1

I am trying to compare a session variable to another string so that i can enable or disable image buttons. i am using asp.net vb with a sql2005 express backend

i was using string.compare to compare the session variable sent from the login page to a string i set to "medev" which is a username in my database, if the condition is true and username "medev" is found i would like to dissable some image buttons. can someone show me how to fix my code or a way to do this? thanks!

Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load

Dim string1 As String
Dim string2 As String

Label1.Text = Session("Username")
Label2.Text = Session("UserId")

string1 = Session("Username")
string2 = "medev"


    If String.Compare(string1, string2, StringComparison.InvariantCultureIgnoreCase) < > 0 Then

        ImageButton1.Enabled = False

        MsgBox("Retrieved variable from masterpage is: " & Session("Username"))

    End If
A: 

String Compare returns 0 if the strings are equal. To evaluate for true change your comparison to = 0 rather than <> 0.

If String.Compare(string1, string2, StringComparison.InvariantCultureIgnoreCase) = 0 Then

If you envision performing such checks frequently to display different portions of a page you might want to break your pages up based on the different types (or levels) of users you expect and redirect them to a particular page upon login. Depending on how similar the pages are between users you'll likely find using master pages and/or user controls to be beneficial.

Ahmad Mageed
oh i understand now i didn't notice the add comment section so i asked the question again..thanks...Ok this is how my problem started..i wanted to build a space in which i can display pictures of a project in it's different stages i pull the rest of the information associated with the customer from a sql2005 exp DB..because i was unable to display the pics associated with the specific user dynamical i chose to have a list of image buttons on a secure page which would represent different clients i would like these buttons to enable or disable based on the passes session(userid)..