Solved

onclick event together with onserverclick event

Posted on 2003-12-03
5
1,418 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
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 125 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

Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

Join & Write a Comment

IP addresses can be stored in a database in any of several ways.  These ways may vary based on the volume of the data.  I was dealing with quite a large amount of data for user authentication purpose, and needed a way to minimize the storage.   …
Welcome my friends to the second instalment and follow-up to our Minify and Concatenate Your Scripts and Stylesheets (http://www.experts-exchange.com/Programming/Languages/.NET/ASP.NET/A_4334-Minify-and-Concatenate-Your-Scripts-and-Stylesheets.html)…
In this tutorial you'll learn about bandwidth monitoring with flows and packet sniffing with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're interested in additional methods for monitoring bandwidt…
This tutorial demonstrates a quick way of adding group price to multiple Magento products.

762 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

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now