Solved

Summary to Detail Page using a Button

Posted on 2014-01-06
3
388 Views
Last Modified: 2014-01-09
I have a summary page which lists events, each with a unique ID. Currently, the user can click on "Edit" and be taken to the detail page to edit the event. What I would like to do is replace "Edit" with a button that goes to a routine which checks to see if the user is logged in before going to the detail page. I'm using Dreamweaver CS4. Is that possible?

Here is the code for the current "Edit" button:

<td width="20" class="hpResults"><div align="center"><a href="eventupdate.asp?ID=<%=(rseventCalendar.Fields.Item("ID").Value)%>"><span class="eventeditLink">Edit</span></a></div></td>

Open in new window


I tried saving the ID but was not successful.
0
Comment
Question by:slegy
3 Comments
 
LVL 70

Assisted Solution

by:Jason C. Levine
Jason C. Levine earned 175 total points
ID: 39760377
Easiest way would be to send all Edit clicks to a new page with a query string of the eventID:

<a href="loggedIn.asp?ID=<%=(rseventCalendar.Fields.Item("ID").Value)%>"><span class="eventeditLink">Edit</span></a>

On the loggedIn.asp page, perform the test to see if the user is logged in (check for cookie, session, whatever you are using to validate) and redirect them to either the edit page or the login page appropriately.
0
 
LVL 82

Accepted Solution

by:
leakim971 earned 175 total points
ID: 39760435
<td width="20" class="hpResults">
      <div align="center">
              <a href="eventupdate.asp?ID=<%=(rseventCalendar.Fields.Item("ID").Value)%>">
                        <span class="eventeditLink">Edit</span>
              </a>
       </div>
</td>

add this in the head section of your page :
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>
<script>
   jQuery(function($) {
         $("a[href^=eventupdate.asp]").click(function(event) {
              var isLoggedIn = null;
              $.ajax({ url:"checkIfLoggedIn.asp", success: function(status) { isLoggedIn = (status=="OK"); }, async:false });
              if( !isLoggedIn ) {
                  event.preventDefault(); // stop!!!!
                  alert("YOU'RE NOT LOGGED IN");
                  // location.href = "/login.asp"; // uncomment to redirect to loggin page
              }
         });
   });
</script>

Open in new window


I used jQuery to simplify the code. We can of course use simple Javascript, it's essentialy a synchronous ajax call.

Your script checkIfLoggedIn.asp should return (and only return) OK if the user is logged.
A simple one :
<%
Response.Write ("OK")
%>

Open in new window

0
 
LVL 52

Expert Comment

by:Scott Fell, EE MVE
ID: 39760456
Are you using dreamweaver's code to log in?  If you are, then you can use the Server Behavior > User Authentication > Restrict Access to Page.  

You will end up with some type of code that looks like
<%
' *** Restrict Access To Page: Grant or deny access to this page
MM_authorizedUsers=""
MM_authFailedURL="good_by_not_logged_in.asp"
MM_grantAccess=false
If Session("MM_Username") <> "" Then
  If (true Or CStr(Session("MM_UserAuthorization"))="") Or _
         (InStr(1,MM_authorizedUsers,Session("MM_UserAuthorization"))>=1) Then
    MM_grantAccess = true
  End If
End If
If Not MM_grantAccess Then
  MM_qsChar = "?"
  If (InStr(1,MM_authFailedURL,"?") >= 1) Then MM_qsChar = "&"
  MM_referrer = Request.ServerVariables("URL")
  if (Len(Request.QueryString()) > 0) Then MM_referrer = MM_referrer & "?" & Request.QueryString()
  MM_authFailedURL = MM_authFailedURL & MM_qsChar & "accessdenied=" & Server.URLEncode(MM_referrer)
  Response.Redirect(MM_authFailedURL)
End If
%>

Open in new window

Make sure that is on the very top of your detail page.
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
ASP and Extracting XML 7 24
window close link 7 32
Hide and Unhide Table 6 24
ASP Error Handler 5 15
In my daily work (mainly using ASP.net), I need to write a lot of JavaScript code. One of the most repetitive tasks I do are the jQuery Ajax calls. You know: (CODE) I don't know if for you it's the same, but for me is soooo tedious to write the …
This demonstration started out as a follow up to some recently posted questions on the subject of logging in: http://www.experts-exchange.com/Programming/Languages/Scripting/JavaScript/Q_28634665.html and http://www.experts-exchange.com/Programming/…
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

685 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question