Wrox Programmer Forums
|
Classic ASP Databases Discuss using ASP 3 to work with data in databases, including ASP Database Setup issues from the old P2P forum on this specific subtopic. See also the book forum Beginning ASP.NET Databases for questions specific to that book. NOT for ASP.NET 1.0, 1.1, or 2.0.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Classic ASP Databases section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old January 26th, 2007, 04:10 PM
Authorized User
 
Join Date: Jan 2007
Posts: 15
Thanks: 0
Thanked 0 Times in 0 Posts
Default perform multiple things with one button

I'm new to ASP, and have looked online and in books for an answer without success. I have a page that displays 40 columns of data with multiple rows so that users can edit survey data (call this page the PARENT). Upon clicking on the SUBMIT button for this page we go to a review page with buttons for EDIT or APPROVE (call this page the CHILD). Edit returns you to the Parent page for futher editing, and approve takes you back to the main menu.

Everything functions regarding page movement and data display.

The problem arrives when I added an onclick to the approve button to execute the SQL stored procedure (it moves the data from a "for review" table to the live table). The SQL procedure works fine, but it gets executed (as near as I can tell) on the parent page when I click on the initial SUBMIT button. I tested this by putting in some JavaScript alerts and then looking at the database tables after each alert popped up (good approach???). My first alert on the child page is immediately after </head>, but the data exists in the live tables by then. I have included snippets of the code below labelled as parent or child pages.

I'm leaning toward the idea that the browser parses through the HTML on the child page prior to executing the javascript, and that the onclick is not really attached to the button and is simply executing (but I'm way outside my comfort zone here).

Thanks in advance for any insight you folks can offer about the behavior I am seeing. Alternate approaches are also appreciated.


Parent Page
<form method="post" action="add_survey_data_loading_ASv2.asp"
      name="add_survey_data_admin_ASv2">
-- contains table code in here which is working
-- code for SUBMIT button shown below is within same form as above
<table border="0" width="700" id="table18" cellspacing="0"
   cellpadding="0" height="20">
   <tr><td width="150" align="left"><b>&nbsp;</b></td>
    <td width="400" align="center"><b>&nbsp;
        <input type="submit" value="Submit Changes"
               name="Submit_Changes"
                   style="font-size: 12pt; font-family: Verdana"
                   tabindex="1"></b></td>
        <td width="150" align="left" ><b>&nbsp;</b></b></td></tr>
</table>
</form>


Child Page
-- there is code to display the data for review and an EDIT button
-- located above this code on the webpage
<FORM METHOD="LINK" ACTION="http://192.168.1.69/main_ASv2.asp">
<table border="0" width="1000" id="table22" cellspacing="0" cellpadding="0" height="25">
  <tr><td width="1000" align="center"><b>&nbsp;
      <INPUT TYPE="submit" VALUE="Approve Changes"
             name="Approve_Changes" style="font-size: 12pt;
              font-family: Verdana" tabindex="3"
   onclick="<%sqlcs="EXEC dbo.CMS_move_data_from_review_to_approved
               @Audit_ID = '" & audit_id & "', @privileges = '" &
               privileges & "', @procedure = 'ADD_NEW'"
               cs.open sqlcs, conn, 2, 2%>"></b></td>
</td></tr>
</table>
</FORM>

 
Old January 26th, 2007, 04:46 PM
Wrox Author
 
Join Date: Oct 2005
Posts: 4,104
Thanks: 1
Thanked 64 Times in 64 Posts
Send a message via AIM to dparsons
Default

Actually,
    Clicking your inital submit button isn't causing your SP to fire, its the loading of the second page that is doing it. Here is why: you state that you added an onclick event to your submit button, while this is true, you added no code to that event.

The reason: Your logic on the child page is a little off. OnClick is a client side event but, you provide server side code as the logic for the onclick.

Simply put this code:
<%sqlcs="EXEC dbo.CMS_move_data_from_review_to_approved
               @Audit_ID = '" & audit_id & "', @privileges = '" &
               privileges & "', @procedure = 'ADD_NEW'"
               cs.open sqlcs, conn, 2, 2%>

is executed as soon as the child page is opened because it is surrounded by <% %> which tells the asp interpeter to run the commands before the page is displayed.

I think your edit button should just be this: <button code....onclick="window.close();"> which will close your child window and return you to your parent page. Clicking on the submit button should cause the child form to post and have the SP executed.

================================================== =========
I will only tell you how to do it, not do it for you.
Unless, of course, you want to hire me to do work for you.
================================================== =========
Read this if you want to know how to get a correct reply for your question:
http://www.catb.org/~esr/faqs/smart-questions.html
^^Took that from planoie's profile^^
^^Modified text taken from gbianchi profile^^
================================================== =========
 
Old January 29th, 2007, 10:44 AM
Authorized User
 
Join Date: Jan 2007
Posts: 15
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Thanks for your help. Your observation about the timing matched my gut feeling. I didn't realize I was mixing client-side and server-side code, so it appears I have more reading to do. Thanks again.






Similar Threads
Thread Thread Starter Forum Replies Last Post
Multiple Lines in Button jmss66 Classic ASP Basics 3 September 21st, 2006 10:01 AM
Multiple function in submit button sougataroy BOOK: Beginning ASP 3.0 2 August 16th, 2006 06:30 PM
Multiple event handlers for a single button monuindia2002 ASP.NET 1.0 and 1.1 Professional 1 October 16th, 2005 11:22 PM
Other things to try Martyn JSP Basics 0 August 29th, 2003 09:44 AM
Multiple Button Effects Bob Bedell Dreamweaver (all versions) 2 August 12th, 2003 07:10 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.