473,406 Members | 2,371 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,406 software developers and data experts.

C# Control Structure with Session

I am having a problem with this control sturcture. I want to hide a
button if the session object is equal to "Staff". I am not getting an
error, the code simply does not work. Help appreciated.
<code>
void Page_Load(object sender, System.EventArgs e)
{
if (Session["WebUser"] == "Staff")
{
//Response.Write (Session["WebUser"]);
Button1.Visible = false;
}

if (!Page.IsPostBack)
{.........
</code>


*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Nov 19 '05 #1
5 1383
What did the line "Response.Write...." print? Also, try something like:

string savedState = (string)this.Session["WebUser"];
if (savedState == "Staff")
{
// .....
}

Nov 19 '05 #2

I can't get it to work. This works:<code>
void Page_Load(object sender, System.EventArgs e)
{
string savedState = (string)this.Session["WebUser"];
if (savedState == "Staff")
{
Response.Write (Session["WebUser"]);
//Button1.Visible = false;
}

if (!Page.IsPostBack)
{...
</code>
So the response.write test line works, but I can't seem to get it to
hide the button for some reason when I use the 2 statements together.
Help appreciated.

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Nov 19 '05 #3
On 20 Feb 2005, Frank Bishop <fb*****@viper.com> postulated in
news:uF**************@TK2MSFTNGP15.phx.gbl:

I can't get it to work. This works:<code>
void Page_Load(object sender, System.EventArgs e)
{
string savedState = (string)this.Session["WebUser"];
if (savedState == "Staff")
{
Response.Write (Session["WebUser"]);
//Button1.Visible = false;
}

if (!Page.IsPostBack)
{...
</code>
So the response.write test line works, but I can't seem to get it to
hide the button for some reason when I use the 2 statements together.
Help appreciated.

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!


You know, I don't like the == used with a string. Just doesn't feel
right.

Have you tried something like:

if (this.Session["WebUser"].ToString().CompareTo("Staff") == 0)
-- ipgrunt
Nov 19 '05 #4

Sorry, you are right. I ran into a case issue too. So I covered that
like this:<code>

void Page_Load(object sender, System.EventArgs e)
{
string savedState1 = Session["WebUser"].ToString();
string savedState2 = savedState1.ToLower();
if (savedState2 == "staff")
{
Button1.Visible = false;
//Response.Write (Session["WebUser"]);
}</code>
Thanks for all the help.
Frank
*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Nov 19 '05 #5
You should use String.Compare(s1, s2, true) and check if it equals 0.

Also, in a previous post you said it _did_ do the response write, but
not hide the button. If that really was true, then how would
case-sensitivity solve anything?

Nov 19 '05 #6

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

Similar topics

9
by: McGeeky | last post by:
Is there a way to get a user control to remember its state across pages? I have a standard page layout I use with a header and footer as user controls. Each page uses the same layout by means of...
10
by: David Fort | last post by:
Hi, I'm upgrading a VB6 app to VB.net and I'm having a problem with a call to a function provided in a DLL. The function takes the address of a structure which it will fill in with values. I...
2
by: DC | last post by:
Hi, I am doing something like this in the ItemCreated event (ASP.Net 1.1): DataGridItem pagerRow = e.Item; TableCell pagerCell = pagerRow.Cells; Control addedControl = new Control();...
0
by: SteveBark | last post by:
Can anyone point me in the right direction as to what control structure I should put in place for the following requirement. I have an Access Server which I have 30 modems connected to. I need to...
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: 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: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

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.