I’m working with (not on) an ASP based auction system (XCAuction) and the client is asking me to do some customization.
Thier chosen template style has the navagation at the bottom of ever page (???) but they would like it at the top as well. The problem, for me, arises because I cannot just include the ASP script that creates the the bottom menu in the top menu because the header template is strictly html.
Now, I could go into every single template page of the system and add the ASP before or after the header, but that would take weeks and be just ugly.
The good thing: The menu has only three choices; main menu, auction help, and login/logout. The ASP script just handles the login/logout decision by reading the cookie (or lack their of)
The bad thing: I know zero javascript! I would run out and buy a book (actually I already have one) but I don’t have time. Any help would be great.
All I need to do is read the cookie and then have the html display the login or logout link depending on what it finds.
This is as far as I have gotten trying to use an example from a javascript site :o
I once did it in ASP .net (with an .ascx control page, which had to appear on each and every page)
This is the code behind a logoff button :
Private Sub BtnLogoff_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BtnLogoff.Click
Dim Cookie As HttpCookie
Cookie = Request.Cookies("ITNN_LoginData")
Cookie.Expires = Now.AddDays(-1)
Response.AppendCookie(Cookie)
If Not Request.QueryString("ITl") Is Nothing And Not Request.QueryString("ITl") = "error404" Then
Response.Redirect("../default.aspx?ITl=" & Request.QueryString("ITl"))
Else
Response.Redirect("../default.aspx")
End If
End Sub
This code actually makes the cookie if it does not exist.
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Me.TDHighlight.Controls.Add(LoadControl("../includes/index_highlight_sub.ascx"))
If Not IsPostBack Then
Dim Cookie As HttpCookie = Request.Cookies("ITNN_LoginData")
If Not Request.Cookies("ITNN_LoginData") Is Nothing Then
BtnLogoff.Visible = True
cellMember.Controls.Add(LoadControl("../includes/index_topright_u_login.ascx"))
Dim qS As New DataRetrievalOne
qS.Retrieve("itnn", "SELECT * from I_User where [username] = '" & CStr(Cookie.Values("Username")) & "' and [password] = '" & CStr(Cookie.Values("UserPass")) & "'")
While qS.ObjDR.Read()
If qS.ObjDR("group") = 5 Then
Dim tabAdm As New TableCell
Dim tabStrp As New TableCell
tabStrp.Text = " | "
tabAdm.Text = "<a href='../admin/default.aspx'>admins</a>"
navBar.Rows(0).Cells.Add(tabStrp)
navBar.Rows(0).Cells.Add(tabAdm)
End If
End While
qS.Close()
Else
BtnLogoff.Visible = False
cellMember.Controls.Add(LoadControl("../includes/index_topright_u_register.ascx"))
TD4.Controls.Clear()
TD4.Controls.Add(LoadControl("../controls/index_prohibited.ascx"))
End If
End If
End Sub
I decided to just scrap the Javascript method alltogether.
The way the XCAuction ASP handles the header is that it reads the header htm file into a var as a text file. It finds where the header should end and the content should begin, it inserts the content, and then it reads in the footer. After all of that, it outputs the var to build the html for the whole page.
Since it does this for every single page, I just entered %loginlogout% in the header htm. Then when I read in the header, I replace that var with the current session state, either logged in or logged out and respective link. The other menu items are static so I don’t have to worry about them.
This whole method of building the pages seems rediculous to me, but I’m not an ASP guy so maybe it’s status quo. Either way, I accomplished my goal without using js, which is fine with me. I’m not one for client side scripting. The Javascript book will go back on the shelf for another day!