READONLY based on cookie value...
I am very new to .NET, so forgive my ignorance. :)
I am probably approaching this in every wrong direction, but for right now, until i can get a real user authentication scheme going (not to mention having to learn how to use code behind...) this will have to do.
Basically, I have an application that has 3 different user levels. The user shall login and the user/pass verified against an Oracle db. If it comes back good, a cookie is set that specifies the user access level. This app will be used on our intranet, and mostly by people who are not going to mess with cookies, so I am not worried about total security (yet... I just need to get this thing out the door for now, and go back and add aforementioned proper user access later).
Sooo... all that to say that I need to have certain field in a form READONLY depending on the user level captured in the cookie. Here is what I have so far (most of the code removed, only displaying one row...):
VB Code:
<%@ Page Language="VB" ContentType="text/html" ResponseEncoding="iso-8859-1" %>
<script language="vb" runat="server">
public sub Page_Load(sender as object, e as eventargs)
MAN_INVOICE_DATE.Text = format(system.datetime.now,"dd-MMM-yy")
CREATION_DATE.Text = format(system.datetime.now, "dd-MMM-yy")
SYS_INVOICE_DATE.Text = format(system.datetime.now, "dd-MMM-yy")
[B]CLIENT_ID.Attributes.Add("onchange","javaScript:this.value = this.value.toUpperCase();")
Dim levelAccess As HttpCookie = Request.Cookies("levelAccess")
Dim userLevel As Byte
userLevel = levelAccess.value
Dim ccmReadOnly as Boolean
Dim dcmReadOnly as Boolean
Select case userLevel
Case 1
ccmReadOnly = "False"
dcmReadOnly = "False"
Case 2
ccmReadOnly = "True"
dcmReadOnly = "False"
Case 3
ccmReadOnly = "True"
dcmReadOnly = "True"
End Select[/B]
end sub
</script>
<html>
<head></head>
<body>
<form method="post" name="form1" runat="server">
<table>
<tr valign="baseline" bgcolor="#99CCFF">
<td align="right" nowrap bgcolor="#99CCFF">CCM Email</td>
<td bgcolor="#99CCFF"><asp:TextBox ID="CCM_EMAIL" TextMode="SingleLine" ReadOnly="<%# response.write(ccmReadOnly) %>" Columns="32" runat="server" />
</td>
<td align="right" nowrap="nowrap">CCM Approval Date</td>
<td><asp:TextBox ID="CCM_DATE" TextMode="SingleLine" ReadOnly="<%# response.write(ccmReadOnly) %>" Columns="8" runat="server" />
</td>
</tr>
</table>
</form>
</body>
</html>
With or without the quotes around the response.write, I get the following error:
BC30451: Name 'ccmReadOnly' is not declared.
Thanks for your help!
Re: READONLY based on cookie value...
This may not make a bit of difference, but you don't need the quotes for True and False.. its a Boolean, and True And False are the only options.. not a "string named false" or a "string named true"
... just saw your post about the "with or without quotes does the same thing".. so never mind....
Re: READONLY based on cookie value...
Moved from VB.NET forum. :)
Re: READONLY based on cookie value...
It's your variables.. they only exist within the sub because of your declarations... once the sub is exited, they disappear... Need to declare the booleans outside the sub... im guessing... never really messed with vb scripting
Re: READONLY based on cookie value...
I see what I did wrong witht he variables, and cannot believe I tried to call that variable from outside the sub. Duh.
So now I am presented with another error:
Compiler Error Message: BC30491: Expression does not produce a value.
Source Error:
Line 278: <td bgcolor="#99CCFF"><asp:TextBox ID="CCM_EMAIL" TextMode="SingleLine" Columns="32" ReadOnly="<%#response.write(ccmReadOnly)%>" runat="server" />
The expression it is referring to, according to the detailed report, is:
target.ReadOnly = CType(response.write(ccmReadOnly),Boolean)
~~~~~~~~~~~~~~~~~~~~~~~~~~~
Still playing with the code - hoping the ASPX God will smile upon me. :)