?
Solved

onclick event together with onserverclick event

Posted on 2003-12-03
5
Medium Priority
?
1,482 Views
Last Modified: 2007-12-19
I wonder if I can use onClick event handler and onserverclick event handler on the same button?
I want after just clicking once on the button to insert an order in the databas and at the same time send info (through hidden fields) to a credit card company, and the user must of course be taken to this company on submitting the order.See my code below. I tried but did not succeed. Do you have any solution?Feel free to edit my code.Thanks in advance.


<form id="Form1" method="post" runat="server">
Fullname:
<input type="text" id="Name" runat="server"></input>
...
<input type="submit" onClick="document.CardService.submit(); onserverclick="BtnSubmit_ServerClick" runat="server" value="Submit" Id="BtnSubmit">
</form>

<form Name="CardService" method="post" action="https://secure_host_name/cgi-bin/hlppay">
<input type="hidden" Id="chargetotal" value='ViewState("TotalAmount")'>
</form>

Private Sub BtnSubmit_ServerClick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BtnSubmit.ServerClick
....'Procedure that inserts an order in database
End Sub
0
Comment
Question by:viktor999
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
5 Comments
 
LVL 28

Expert Comment

by:mmarinov
ID: 9868184
You can not have more than one form in your web page in .net
so what you want to do can be done all in the BtnSubmit_ServerClick using Context object
by it you can transfer data between pages
example
Context["item"] = yourdatafromhiddeninput

After setting this you can use Server.Transfer to go to another page and use data in Context["item"]

using Server.Transfer is like Server.Execute

B..G
0
 
LVL 12

Accepted Solution

by:
roverm earned 500 total points
ID: 9869010
A solution might be adding some code (javascript) to the button.
Then let this javascript open a seperate window using window.open().
Something like this:

In your page_load:

btSubmit.Attributes.Add("onclick") = "javascript:return opencreditcard();"

And add this to your aspx page:

<script language="javascript">
  function opencreditcard() {
  //replace these variables!!
  var t=document.forms(0).chargetotal; if (!t) {alert('Total amount not found!');return false;}
  //now open a seperate window
  window.open('https://secure_host_name/cgi-bin/hlppay?chargetotal='+t.value);
  }
</script>

Of course, the window.open function can also open one of your aspx pages with all nessacary information in it.

Hope this helps!

D'Mzz!
RoverM
0
 
LVL 29

Expert Comment

by:David H.H.Lee
ID: 9871884
viktor999,

Here's my version to solve your problems
=======================================
<script runat="server" language="vb">
  Sub btnSubmit_Click(sender As Object, e As EventArgs)
      'Insert YOUR DB Processing
   End Sub
   
   Sub Page_Load(sender As Object, e As EventArgs)
        btnSubmit.Attributes.Add("onClick","javascript:Submit()")
   End SUb
</script>

<HTML>
    <HEAD>
         <script language="javascript">
         function Submit()
         {
              //Do client-side processing to handle hidden field ,add here
              document.getElementById("btnSubmit").click(); //server-processing
         }
         </script>
    </HEAD>
    <body>
         <form runat="server">
             <asp:textbox id="Name" runat="server"/><br>
              <asp:Button id="btnSubmit" onclick="btnSubmit_Click" Text="submit" runat="server" />
         </form>
    </body>
</HTML>

If you want to use Request.Form() like what you done in classical way. Take a look my post here:
http://oldlook.experts-exchange.com/Web/Web_Languages/ASP/Q_20799963.html

It's work for me as well. Hope that solve your problems too.

Regards
x_com
0
 
LVL 96

Expert Comment

by:Bob Learned
ID: 10287382
No comment has been added lately, so it's time to clean up this TA.
I will leave the following recommendation for this question in the Cleanup topic area:

Accept: roverm {http:#9869010}

Please leave any comments here within the next seven days.
PLEASE DO NOT ACCEPT THIS COMMENT AS AN ANSWER!

TheLearnedOne
EE Cleanup Volunteer
0

Featured Post

Free Backup Tool for VMware and Hyper-V

Restore full virtual machine or individual guest files from 19 common file systems directly from the backup file. Schedule VM backups with PowerShell scripts. Set desired time, lean back and let the script to notify you via email upon completion.  

Question has a verified solution.

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

A basic question.. “What is the Garbage Collector?” The usual answer given back: “Garbage collector is a background thread run by the CLR for freeing up the memory space used by the objects which are no longer used by the program.” I wondered …
This document covers how to connect to SQL Server and browse its contents.  It is meant for those new to Visual Studio and/or working with Microsoft SQL Server.  It is not a guide to building SQL Server database connections in your code.  This is mo…
Monitoring a network: how to monitor network services and why? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the philosophy behind service monitoring and why a handshake validation is critical in network monitoring. Software utilized …
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…
Suggested Courses

777 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