Solved

onclick event together with onserverclick event

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

Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

Question has a verified solution.

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

In my previous two articles we discussed Binary Serialization (http://www.experts-exchange.com/A_4362.html) and XML Serialization (http://www.experts-exchange.com/A_4425.html). In this article we will try to know more about SOAP (Simple Object Acces…
More often than not, we developers are confronted with a need: a need to make some kind of magic happen via code. Whether it is for a client, for the boss, or for our own personal projects, the need must be satisfied. Most of the time, the Framework…
This Micro Tutorial will give you a basic overview how to record your screen with Microsoft Expression Encoder. This program is still free and open for the public to download. This will be demonstrated using Microsoft Expression Encoder 4.

822 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