travishaberman
asked on
How do I run some code on the loading of a page (ASP)
I am trying to use cookies and I am new to web page development. My thought is that when the page loads I should check for my cookie and adjust the formatting of the page acordingly. So if a user is loged in certain fields will be availible and some will not. I have figured out the cookie thing mostly but I cant figure out how to get the code to run before a button on the page is clicked. I need to run my statements before the user sees what is on the page - before a button is clicked. Where? How? do I put in the code I need?
Here is a tidbit from the start of my page...
Thank you,
TH
CODE
========================== ========== ========== ========== ========== ========== ========== ========== ======
<%@ Page Language="VB" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<script runat="server">
' <------------------ need to run this code first !!!!!!!!!!!!!!!!!!!!!!!!!! !!!!!!!!!! !!!!!!!!!! !!!!!!!
' <------------------ need to run this code first !!!!!!!!!!!!!!!!!!!!!!!!!! !!!!!!!!!! !!!!!!!!!! !!!!!!!
If Request.Cookies("Preferenc es").HasKe ys Then ' <------------------ need to run this code first !!!!!!!!!!!!!!!!!!!!!!!!!! !!!!!!!!!! !!!!!!!!!! !!!!!!!
' <------------------ need to run this code first !!!!!!!!!!!!!!!!!!!!!!!!!! !!!!!!!!!! !!!!!!!!!! !!!!!!!
TextBox_Password.Visible() = False ' <------------------ need to run this code first !!!!!!!!!!!!!!!!!!!!!!!!!! !!!!!!!!!! !!!!!!!!!! !!!!!!!
TextBox_UserName.Visible() = False ' <------------------ need to run this code first !!!!!!!!!!!!!!!!!!!!!!!!!! !!!!!!!!!! !!!!!!!!!! !!!!!!!
' <------------------ need to run this code first !!!!!!!!!!!!!!!!!!!!!!!!!! !!!!!!!!!! !!!!!!!!!! !!!!!!!
' <------------------ need to run this code first !!!!!!!!!!!!!!!!!!!!!!!!!! !!!!!!!!!! !!!!!!!!!! !!!!!!!
End If ' <------------------ need to run this code first !!!!!!!!!!!!!!!!!!!!!!!!!! !!!!!!!!!! !!!!!!!!!! !!!!!!!
' <------------------ need to run this code first !!!!!!!!!!!!!!!!!!!!!!!!!! !!!!!!!!!! !!!!!!!!!! !!!!!!!
Sub Button_Submit_Book_Click(B yVal sender As Object, ByVal e As System.EventArgs)
'gather user entry data
Dim strUserName As String
Dim strPassword As String
If Request.Cookies("Preferenc es").HasKe ys() Then
strUserName = Request.Cookies("Preferenc es")("User Name")
strPassword = Request.Cookies("Preferenc es")("Pass word")
End If
If Not Request.Cookies("Preferenc es").HasKe ys Then
strUserName = TextBox_UserName.Text
strPassword = TextBox_Password.Text
End If
Dim strBook_Title As String = TextBox_Book_Title.Text
Dim strBook_Auther As String = TextBox_Book_Author.Text
Dim strBook_ISBN As String = TextBox_Book_ISBN.Text
Dim Flag_account_password_exis t As Boolean
Thank you,
Here is a tidbit from the start of my page...
Thank you,
TH
CODE
==========================
<%@ Page Language="VB" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<script runat="server">
' <------------------ need to run this code first !!!!!!!!!!!!!!!!!!!!!!!!!!
' <------------------ need to run this code first !!!!!!!!!!!!!!!!!!!!!!!!!!
If Request.Cookies("Preferenc
' <------------------ need to run this code first !!!!!!!!!!!!!!!!!!!!!!!!!!
TextBox_Password.Visible()
TextBox_UserName.Visible()
' <------------------ need to run this code first !!!!!!!!!!!!!!!!!!!!!!!!!!
' <------------------ need to run this code first !!!!!!!!!!!!!!!!!!!!!!!!!!
End If ' <------------------ need to run this code first !!!!!!!!!!!!!!!!!!!!!!!!!!
' <------------------ need to run this code first !!!!!!!!!!!!!!!!!!!!!!!!!!
Sub Button_Submit_Book_Click(B
'gather user entry data
Dim strUserName As String
Dim strPassword As String
If Request.Cookies("Preferenc
strUserName = Request.Cookies("Preferenc
strPassword = Request.Cookies("Preferenc
End If
If Not Request.Cookies("Preferenc
strUserName = TextBox_UserName.Text
strPassword = TextBox_Password.Text
End If
Dim strBook_Title As String = TextBox_Book_Title.Text
Dim strBook_Auther As String = TextBox_Book_Author.Text
Dim strBook_ISBN As String = TextBox_Book_ISBN.Text
Dim Flag_account_password_exis
Thank you,
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Never doubt the power of Google.
You can check
Request.Cookies("Preferenc es")<>''
if I'm correct, but if you want to check if a Preferences cookie has a certain key, you'd do
Request.Cookies("Preferenc es")("keyN ame")<>''
You can check
Request.Cookies("Preferenc
if I'm correct, but if you want to check if a Preferences cookie has a certain key, you'd do
Request.Cookies("Preferenc
ASKER
hmmm.. that didn't quite do it.. I tried, but it says.. but I get an "expresson expected"
any more thoughts?
any more thoughts?
Ah, let's see...
(Playing around here since not TOO great at ASP)
If Request.Cookies("Preferenc es") Is Nothing Then
Cookie Does not Exist
(Playing around here since not TOO great at ASP)
If Request.Cookies("Preferenc
Cookie Does not Exist
ASKER
That did it!!!
Thank you much,
-TH
Thank you much,
-TH
No prob, glad to help :)
ASKER
If Request.Cookies("Preferenc
...
...
What I want to do is check to see if the cookie is there at all..
any thoughts?
if no.. then I will just accept your last answer..
Thanks!
-TH