473,899 Members | 3,752 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Submit Form via code behind?

2 New Member
I know I know, why would I want to submit the form from server-side code, if the only way to get to the server-side code was BY submitting the form. But that's just it, when the code-behind page_load event fires it doesn't really "submit" the form as I would like it submitted.

Here's my problem, I made a shopping cart for a website, and to get the information securely paid for I need to send a form to paypal using method="post" and action="big long url". In asp.net I can't have multiple forms with runat="server" on the same web page, so what I did was create a new page with the only form being the send-to-paypal form, and the page_load event handler in the codebehind populates the form tag with the correct transaction information (item names, prices, shipping, etc). Currently I have to have it create a button here too with type="submit". You have to click the button before the transaction is sent to paypal. Is there a way to make the Page_Load event fire the form's submit event so I don't have to require a button click?

Here's the html part of the new page with the form:

Expand|Select|Wrap|Line Numbers
  1. <div id="SendPaypalInfo" runat="server">
  2.             <FORM action="https://www.paypal.com/cgi-bin/webscr" method="post" runat="server"></FORM>
  3.         </div>
  4.  

and then here's the current Page_Load codebehind:

Expand|Select|Wrap|Line Numbers
  1. Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
  2.         If Not Page.IsPostBack Then
  3.             Dim TextToSend As String = ""
  4.             Dim a As Integer
  5.  
  6.             RetrieveSessionVariables()
  7.  
  8.             TextToSend = "<form name=""PaypalSubmitForm"" action=""https://www.paypal.com/cgi-bin/webscr"" method=""post"" runat=""server"">"
  9.             TextToSend = TextToSend & "<input type=""hidden"" name=""cmd"" value=""_cart"">"
  10.             TextToSend = TextToSend & "<input type=""hidden"" name=""business"" value=""EDITED"">"
  11.             TextToSend = TextToSend & "<input type=""hidden"" name=""upload"" value=""1"">"
  12. TextToSend = TextToSend & "<input type=""submit"" value=""Click Here""></form>"
  13.  
  14.  
  15.             Me.SendPaypalInfo.InnerHtml = TextToSend
  16.  
  17.         End If
  18.     End Sub

Can i submit the form in that very same page_load event? i don't want them to have to click that button :(
May 2 '06 #1
16 19091
NathyZif
2 New Member
Can anyone help me out on this? :\


I was thinking, maybe I could put some kind of javascript on_load function in the body tag of my site, and it would be executed after asp creates the page's content, would that work? If so, how do i make a javascript on_load event :X
May 2 '06 #2
NETSP
8 New Member
Were you able to resolve this issue? If yes, how? I am looking for an answer as well !!!
Nov 13 '07 #3
r035198x
13,262 MVP
Were you able to resolve this issue? If yes, how? I am looking for an answer as well !!!
The details of this problem are quite strange. Submitting a form as the page loads means submitting a form without taking any user input at all which brings to question the reason for the existence of the form in the first place. It's possible of course to call a Javascript function onload of a page that submits a form on that page.
Nov 13 '07 #4
NETSP
8 New Member
Ok. My issue is bit different.
I have this form

<form name='test' id='test' runat='server'>
<input type='text' id='uName' name='uName'/>
<input type='text' id='pwd' name='pwd' />
<input type="submit" name="submit" ID="submit" value="submit" />
</form>

Now, my process is something like this:

1. Enter username, password and click 'Submit'
2. On the server side, do some authentication process (this I cannot do client side, because the process checks for something by sending a request to some server and receives the response)
3. If the response is valid, then submit this form.

Now, somebody tell me, how can I submit this form either using javascript function or through code-behind.
Nov 13 '07 #5
r035198x
13,262 MVP
Ok. My issue is bit different.
I have this form

<form name='test' id='test' runat='server'>
<input type='text' id='uName' name='uName'/>
<input type='text' id='pwd' name='pwd' />
<input type="submit" name="submit" ID="submit" value="submit" />
</form>

Now, my process is something like this:

1. Enter username, password and click 'Submit'
2. On the server side, do some authentication process (this I cannot do client side, because the process checks for something by sending a request to some server and receives the response)
3. If the response is valid, then submit this form.

Now, somebody tell me, how can I submit this form either using javascript function or through code-behind.
So on submit call a Javascript function which calls a server result through AJAX. You can then submit the form from that Javascript function based of the value of the returned result.
Nov 13 '07 #6
NETSP
8 New Member
That is exactly what I am trying to do. I am using AJAX to retrieve the response and trying to submit the form. Since I have runat="server" in the <form> tag, I am unable to submit the form through JavaScript function. See below.

<script language="javas cript">
function submitf() //calling this function in onClick event of Submit button
{
Default.actuate Authenticate(ch eck_CallBack);
}

function check_CallBack( response)
{
if(response.val ue != "ERROR") //authentication works fine..
{
document.frmLog in.method = "post";
document.frmLog in.action = document.frmLog in.hdnTmpTarget .value;
document.frmLog in.submit();
}
}
</script>
Nov 13 '07 #7
r035198x
13,262 MVP
That is exactly what I am trying to do. I am using AJAX to retrieve the response and trying to submit the form. Since I have runat="server" in the <form> tag, I am unable to submit the form through JavaScript function. See below.

<script language="javas cript">
function submitf() //calling this function in onClick event of Submit button
{
Default.actuate Authenticate(ch eck_CallBack);
}

function check_CallBack( response)
{
if(response.val ue != "ERROR") //authentication works fine..
{
document.frmLog in.method = "post";
document.frmLog in.action = document.frmLog in.hdnTmpTarget .value;
document.frmLog in.submit();
}
}
</script>
Any reason why the form should have the runat server tag in this case?
Nov 13 '07 #8
NETSP
8 New Member
If you don't specify runat="server", the AJAX method won't be executed at all. . It fails to call the method which is in the code behind.
Nov 13 '07 #9
r035198x
13,262 MVP
If you don't specify runat="server", the AJAX method won't be executed at all. . It fails to call the method which is in the code behind.
But of course! Sorry about that. My very bad.
Now you said it's not working. If you put an alert in your code to show
the value of document.frmLog in.hdnTmpTarget .value does it give the correct value?
Nov 13 '07 #10

Sign in to post your reply or Sign up for a free account.

Similar topics

1
2240
by: Tony Hedge | last post by:
Hello, I hope some one can answer this for me. I am using .NET version 1.0 on Windows 2000Pro and I am getting an error when doing a form submit from an HTML control. Please look at the following brief code example: I have two aspx file WebForm1.aspx and WebForm2.aspx. WebForm1 has the following elements:
5
10993
by: Scott | last post by:
How can I tell a form to submit itself in the code-behind in vs.net? In other words, in javascript I can do blah.submit() - how do I do this in vs.net code-behind?
0
1560
by: Niks | last post by:
Hi, I am creating a simple .aspx page to add some fields with validation. I have used different .NET validations like REquiredFieldValidator, RegularExpressionValidator and showed the summary in the bulleted list on top. I have 3 text boxes, and two RadioButtonList. and 3 buttons. One for Submit, Reset and Exit. If submit is pressed page should be validated and submit (insert into
3
2610
by: Arun K | last post by:
Hi, I am creating a simple .aspx page to add some fields with validation. I have used different .NET validations like REquiredFieldValidator, RegularExpressionValidator and showed the summary in the bulleted list on top. I have 3 text boxes, and two RadioButtonList. and 3 buttons. One for Submit, Reset and Exit. If submit is pressed page should be validated and submit (insert into
10
3070
by: Perry van Kuppeveld | last post by:
Hi, I have a problem with formatting a table including text fields wich can contain up to 255 chars. I need a table with 3 columns: - First column 50 % over the with a rowspan of the total number of rows. - Second column 25 %, no rowspan - Third column 25 %, no rowspan
6
5670
by: milkyway | last post by:
Hello there, I have the following code (written in Javascript) for posting of a form on the client side: .... var f2 = document.forms; f2.method = "post"; f2.submit();
3
1469
by: PJ6 | last post by:
When I have client-side script like this - document.forms.submit('test') how do I access, from server-side code, the value I put in the submit method? Also, is it possible to get the control's containing form name so I can emite script like this -
3
5073
by: Anthony | last post by:
I have a form on a web page that requires to click on a button to submit the information. I have two questions about changing this form: 1. Is there a way that I can change the script so that the form can be submitted by hitting the enter key? 2. Is there a way that I can have the Username and Password boxes cleard after the form is submitted? You probably don't need the code for the form as it is pretty basic but here it is just in...
10
8634
by: The Natural Philosopher | last post by:
I am coding up a bit of javascript stuff, and have managed to stumble my way through most of what I want.. But this one has got me stumped. I call submit() and get a javascript error 'Submit not defined' in Firefox.. My very expensive javascript Bible assures me its built in ..so where oh where have I FSCKED up?
0
9997
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9843
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10863
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10971
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10494
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
8039
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5887
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
4720
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
3317
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.