Solved

onclick event together with onserverclick event

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

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.   …
Many of us here at EE write code. Many of us write exceptional code; just as many of us write exception-prone code. As we all should know, exceptions are a mechanism for handling errors which are typically out of our control. From database errors, t…
This video explains how to create simple products associated to Magento configurable product and offers fast way of their generation with Store Manager for Magento tool.
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…

932 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

11 Experts available now in Live!

Get 1:1 Help Now