Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

ASP.NET Forum


You are currently viewing our ASP.NET Forum as a guest. Please register to participate.
Login



Reply
Code for button to refresh page after inserting data in sql db
Old 04-26-2007, 11:36 PM Code for button to refresh page after inserting data in sql db
wacara's Avatar
Novice Talker

Posts: 14
Name: Wanda
Location: Belvidere, IL
Trades: 0
I am creating an application where when the user has answered all questions and hit the 'add new item' button, the data is inserted into the database and the page will refresh so the user can fill it in again for the next item on the quote. I need this to happen continuously until they hit the 'finish' button which will then insert the data and also send the email. I have everything working except for the 'add new item' button. Can anyone help me understand how to have this button insert the data into the database and refresh for the next entry?

Here's my insert statement...

Code:
strSQL = "INSERT into cyl.dbo.Quote_Requirements (" _
           & "Cust_ID, " _
           & "qty_per_ord, " _
           & "qty_per_yr, " _
           & "t_price, " _    
           & "quoted, " _
           & "q_num, " _
           & "built, " _
           & "Serial_num, " _
           & "model_num,  " _
           & "spec_mods, " _
           & "design_built, " _
           & "match_design, " _
           & "mfg_name, " _
           & "service, " _
           & "series, " _
           & "bore, " _
           & "rod_dia, " _
           & "wk_stroke, " _
           & "stroke_tol_plus, " _
           & "stroke_tol_neg, " _
           & "lholding, " _
           & "hyd_shock, " _
           & "low_friction, " _
           & "press_rise, " _          
           & "dbl_rod, " _
           & "press_rod_end, " _
           & "press_cap_end, " _
           & "s_extend, " _
           & "s_retract, " _
           & "rod_end_type, " _
           & "rod_end_size, " _
           & "rod_end_loc, " _
           & "cap_end_type, " _
           & "cap_end_size, " _
           & "cap_end_loc, " _
           & "bolt_on, " _
              & "bom_adder, " _
           & "bom_spec, " _
           & "integral, " _
           & "icm_adder, " _
           & "icm_spec, " _
           & "fluid_type, " _
           & "oper_temp, " _
           & "pseal_type, " _
           & "rseal_type, " _
           & "mtg_styles, " _
           & "mtg_mode, " _
           & "load_guide, " _
           & "cush_cap, " _
           & "cush_head, " _
           & "rod_speed, " _
           & "load_push, " _
           & "load_pull, " _
           & "cycle_rate, " _
           & "cycle_duty, " _
           & "side_load, " _
           & "rod_position, " _
           & "environment, " _
           & "sgl_act, " _
           & "pre_load, " _
           & "press_avail, " _
           & "final_load, " _
           & "spec_matl, " _
           & "spec_paint, " _
           & "draw_num, " _
           & "rev_num, " _
           & "elec_req, " _
           & "transducer,  " _
           & "trans_comments, " _
           & "thaz_env, " _
           & "tnema_enc, " _
           & "TnemaRate, " _
           & "safe_trans, " _
           & "AnaOut, " _
           & "DigOut, " _
           & "interrogation, " _
           & "recirc, " _
           & "format, " _
           & "resolution, " _
           & "performance, " _
           & "opts, " _
           & "protocol, " _
           & "baud_rate, " _
           & "baud_res, " _
           & "switches, " _
           & "switch_comments, " _
           & "shaz_env, " _
           & "snema_enc, " _
           & "SnemaRate, " _
           & "safe_switch, " _
           & "ACSwitchLoc, " _
           & "DCSwitchLoc, " _
           & "connector, " _
           & "electron) " _
           & "values (" & SESSION("CustId") & ", ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)"
And here's the code for the button...

Code:
 <div align="center">
<input type="button" onClick="modalWin2()"name="button" value="Attach Documents"><br><br>
<input type="submit" name="button" value="Add Another Item?" ?onClick="document.reload."?> This is where I have my question...what should I put in the onClick function????


<input type="submit" name="button" value="Finish" onClick="return validateRadioButton();">
<input type="reset" name="Reset" value="Clear">
</div>
</FORM>
Any help would be greatly appreciated.
__________________
you gotta see it before you see it or you never will see it...
wacara is offline
Reply With Quote
View Public Profile Visit wacara's homepage!
 
 
Register now for full access!
Old 04-27-2007, 03:58 AM Re: Code for button to refresh page after inserting data in sql db
chrishirst's Avatar
Missing! presumed drunk.

Posts: 41,519
Name: Chris Hirst
Location: Blackpool. UK
Trades: 0
The very last you want in there is as document.reload, as this is the javascript equivalent of pressing F5 to refresh the page.


There really is no simple answer to what you should put in the onClick event as it will depend on what item you are going to add next.

Without getting too deep into this as it would involve several hours of coding and testing, so this is just first impressions.

Create a javascript class prototype for the form element properties and populate it with the names, id, values, types, text etc for each of the form items required. This is simpler than trying to keep several arrays in sync and can be done quite easily in the ASP that generates the page.
Your add item function now simply needs to get the details from the next class element in the sequence then insert the required element into the form.

One question is;
Do these items change depending on the answers given ?

If not I wouldn't personally set a form up this way.

Consider the user aspect
How do they know when to stop adding items and hit "Finish"? It maybe that one item down the list is important and they won't know where it is.

A better solution for usability is to offer your question form first, then when that is completed and submitted, pass those answers into hidden fields and present the user with the requirements for this part of the process.

When that is complete THEN submit the whole lot and run your insert & email code
__________________
Chris. ->> Links are advertising NOT optimising!! <<-
A foolish consistency is the hobgoblin of little minds
Thought for today:- I SEO the only industry where all the cowboys are Indians?
chrishirst is online now
Reply With Quote
View Public Profile Visit chrishirst's homepage!
 
Old 04-28-2007, 05:41 AM Re: Code for button to refresh page after inserting data in sql db
ForrestCroce's Avatar
Half Man, Half Amazing

Posts: 3,023
Name: Forrest Croce
Location: Seattle, WA
Trades: 0
And for the record, you should use a stored procedure to do the insert. That's a really big query you're constructing - if it's on the fly, it will be difficult if you ever need to debug it - and a lot of text data that needs to get sent between IIS and SQL Server for the insert command. You need to send the data values regardless, but you could save an insert command that takes a bunch of parameters into the database as a stored procedure, and then just call it by name instead of having to list all the fields in the table. So you might send 30 bytes in place of a kb or two of SQL code ... if this happens a lot, it can slow your application down. Also, if you change the name of one of the fields, or get rid of it, you can change the stored procedure without having to change your application code.

You could navigate back to the same page and use a query string to decide whether someone wants to add something, or finish.
__________________

Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
ForrestCroce is offline
Reply With Quote
View Public Profile Visit ForrestCroce's homepage!
 
Old 04-28-2007, 09:19 PM Re: Code for button to refresh page after inserting data in sql db
ADAM Web Design's Avatar
Canadastaninianite

Posts: 5,938
Name: Adam for web page design, not program
Location: Toronto, Ontario, Canada
Trades: 0
Have two submit buttons, both named the same thing (in my sample, I named them Form_Action) :
Code:
<input type="submit" name="Form_Action" value="Add More Items" />
<input type="submit" name="Form_Action" value="Finish" />
After you've inserted the query (which is usually a matter of opening up your database and executing the query you've already compiled), do something like this:
Code:
Dim Form_Action
Form_Action = Request.Form ("Form_Action")
if Form_Action = "" then
     (Reload Form here)
else
     (All Finished)
end if
You have to make sure that your form calls itself for processing though, or it won't work.
__________________

Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
(my blog)


Please login or register to view this content. Registration is FREE
(with proof)

Last edited by ADAM Web Design; 04-28-2007 at 09:20 PM..
ADAM Web Design is offline
Reply With Quote
View Public Profile Visit ADAM Web Design's homepage!
 
Old 04-30-2007, 04:31 PM Re: Code for button to refresh page after inserting data in sql db
wacara's Avatar
Novice Talker

Posts: 14
Name: Wanda
Location: Belvidere, IL
Trades: 0
The form is setup so that the user does know when to hit finish. The insert code you are looking at comes from the verify page not the page that the user will be looking at. This is the page that currently has the hidden fields and when the finish button is hit then the insert happens, the email is sent and the thank you page is shown. That is working just great. I'm just having the problem as to how do I make it hold all the answers or (can I) until the user is finished?

Some of the items will change depending on the answer. If a yes answer is given to certain questions, more information will be requested.

This is in response to Chrishirst's post.
__________________
you gotta see it before you see it or you never will see it...

Last edited by wacara; 04-30-2007 at 04:32 PM.. Reason: additional info
wacara is offline
Reply With Quote
View Public Profile Visit wacara's homepage!
 
Old 04-30-2007, 04:39 PM Re: Code for button to refresh page after inserting data in sql db
wacara's Avatar
Novice Talker

Posts: 14
Name: Wanda
Location: Belvidere, IL
Trades: 0
Quote:
Originally Posted by ADAM Web Design View Post
Have two submit buttons, both named the same thing (in my sample, I named them Form_Action) :
Code:
<input type="submit" name="Form_Action" value="Add More Items" />
<input type="submit" name="Form_Action" value="Finish" />
After you've inserted the query (which is usually a matter of opening up your database and executing the query you've already compiled), do something like this:
Code:
Dim Form_Action
Form_Action = Request.Form ("Form_Action")
if Form_Action = "" then
     (Reload Form here)
else
     (All Finished)
end if
You have to make sure that your form calls itself for processing though, or it won't work.
Thanks Adam for the response...
I had written the following code before...
Code:
 
Sub CmdWhichButton_OnClick()
Dim button
button = Request.Form("button")
If Request.Form("button") = "Add Another Item?" then
 submit
else
 response.Redirect(QReqMtgInfoVerify.asp)
end if
End Sub
Am I going in the right direction or how should I modify it?
__________________
you gotta see it before you see it or you never will see it...
wacara is offline
Reply With Quote
View Public Profile Visit wacara's homepage!
 
Reply     « Reply to Code for button to refresh page after inserting data in sql db
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 0.24611 seconds with 12 queries