Solved

onclick event together with onserverclick event

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

Enroll in May's Course of the Month

May’s Course of the Month is now available! Experts Exchange’s Premium Members and Team Accounts have access to a complimentary course each month as part of their membership—an extra way to increase training and boost professional development.

Question has a verified solution.

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

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)…
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…
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…

734 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