how can i run an html form button on page load? - asp.net

i want to run the submit button when the page loads
Here is my form, it redirect to paypal and i want to run on page load
<head id="Head1" runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server" action="<%= ConfigurationManager.AppSettings["PayPalSubmitUrl"] %>"
method="post" >
<input type="hidden" name="cmd" value="_cart"/>
<input type="hidden" name="upload" value="1"/>
<input type="hidden" name="business" value="<%= ConfigurationManager.AppSettings["PayPalEmailAddress"] %>"/>
<input type="hidden" name="item_name_1" value="Shopping_Cart"/>
<input type="hidden" name="amount_1" value="<%=Session["Total"].ToString() %>" />
<input type="hidden" name="currency_code" value="EUR" />
<input type="submit" id="submit" runat="server" value="PayPal" />
</form>
</body>
</html>

Use some Jquery and Javascript to submit the form as soon as the document is ready.
$(document).ready(function() {
document.forms["form1"].submit();
});

Related

asp.net form with action url and button click not working

I am integrating payment gateway in my product. I have to submit a page to third party payment provider. In the page I have asp.button on the click event I want to store the username and amount in the session,When I click the button the page posting to the action url, my click event is not called.
How can I get the value from session and then I want to post the page.
here is the code
Regards
Arun
<form runat="server" method="post" action="https://secure.ogone.com/ncol/test/order.asp" id="form1" name="form1" >
<!-- General information for the order -->
<input type="hidden" name="orderID" value="34567"/>
<input type="hidden" name="pspid" value="TESTMAS"/>
<input type="hidden" name="version" value="ncol_2.0"/>
<input type="hidden" name="language" value="en_US"/>
<input type="hidden" name="currency" value="EUR"/>
<input type="hidden" name="weightunit" value="kg"/>
<input type="hidden" name="accepturl" value="http://localhost:57249/pages/acceptPayment.aspx"/>
<input type="hidden" name="exceptionurl" value="http://localhost:57249/payment/pages/exception.aspx"/>
<input type="hidden" name="declineurl" value="http://localhost:57249/payment/pages/decline.aspx"/>
<input type="hidden" name="cancelurl" value="http://localhost:57249/payment/pages/cancel.aspx"/>
<input type="hidden" name="homeurl" value="http://localhost:57249/payment/updatePayment.aspx"/>
<input type="hidden" name="catalogurl" value="http://localhost:57249/payment/updatePayment.aspx"/>
<input type="hidden" name="SHASign" value="SHA-1"/>
<!-- or Template Page -->
<input type="hidden" name="TP" value="<Your template page URL>"/>
<input type="hidden" name="itemid" value="1" />
<input type="hidden" name="itemname" value="Papercut Balance updation" />
<input type="hidden" name="itemdesc" value="Papercut Balance updation" />
<input type="hidden" name="taxincluded" value="0" />
<input type="hidden" name="itemvatcode" value="1" />
<input type="hidden" name="itemvat" value="" />
<input type="hidden" name="itemcomments" value="Papercut Balance updation" />
<input type="hidden" name="itemquant" value="1" />
<!-- First item of the order -->
<table>
<tr>
<td>username</td>
<td> <asp:TextBox ID="txtusername" Text="" runat="server"></asp:TextBox></td>
</tr>
<tr>
<td>Payable Amount</td>
<td> <asp:TextBox ID="itemprice" Text="" runat="server"></asp:TextBox></td>
</tr>
<tr>
<td colspan="1" >
<asp:Button ID="Button1" runat="server" Text="ProceedToPay" OnClick="Button1_Click" />
</td>
</tr>
</table>
</form>
protected void Button1_Click(object sender, EventArgs e)
{
String userName = Request["txtusername"];
Double amount = Convert.ToDouble(Request["itemprice"]);
try
{
Session["username"] = userName;
Session["amount"] = amount;
}
catch (Exception e2)
{
System.Diagnostics.Debug.WriteLine(e2.Message + " " + e2.Source);
}
}

Submit form that posts to another site

I have an online banking login that I'm trying to take from an old client site and put on their new site. If I copy the form and paste it into my new site, it just reloads the page when submitted. I've tried to change it to an asp.net form using the appropriate and other applicable tags with the same result.
If I take the form and put it in a simple index.html file, it submits and takes me to the correct external site.
I was unable to set the ID & values with the asp.net form and that may be one of the issues.
Any help is appreciated.
Here is the HTML form version that works in .html page that needs to work in .aspx page:
<form action="some external site" method="POST" autocomplete="OFF" target="_top">
<input type="hidden" name="sssid" value="my value">
<input type="hidden" name="iid" value="another value">
<div class="field-container">
<label for="aid" id="aid-label">Access ID</label>
<input name="aid" id="aid" type="text" size="8" onFocus="toggle_label(this, 'focus');" onBlur="toggle_label(this,'blur');" />
</div>
<div class="field-container">
<label for="passcode" id="passcode-label">Passcode</label>
<input name="passcode" id="passcode" type="password" size="8" onFocus="toggle_label(this, 'focus');" onBlur="toggle_label(this,'blur');"/>
</div>
<div class="form-row">
<input type="submit" name="Submit" value="Go" class="button">
</div>
</form>
Here is my asp.net form version that I tried:
<form action="some external site" method="POST" autocomplete="OFF" target="_top">
<input type="hidden" name="sssid" value="some value">
<input type="hidden" name="iid" value="another value">
<asp:TextBox runat="server" ID="sssid" CssClass="form-control" type="hidden" ClientIDMode="Static"></asp:TextBox>
<asp:TextBox runat="server" ID="iid" CssClass="form-control" type="hidden" ClientIDMode="Static"></asp:TextBox>
<div class="form-group">
<asp:Label runat="server" id="lblAccessID"></asp:Label>
<asp:TextBox runat="server" ID="txtAccessID" CssClass="form-control"> </asp:TextBox>
</div>
<div class="form-group">
<asp:Label runat="server" id="lblPassCode"></asp:Label>
<asp:TextBox runat="server" ID="txtPasscode" CssClass="form-control" TextMode="Password"></asp:TextBox>
</div>
<button type="submit" class="btn btn-blue">GO
<img src="/Content/img/icon-sm-arrow.png" alt="" />
</button>
</form>
My asp.net form code behind:
protected void Page_Load(object sender, EventArgs e)
{
txtAccessID.Attributes.Add("placeholder", "Access ID");
txtPasscode.Attributes.Add("placeholder", "Passcode");
}
I had to use the following to post this correctly:
<asp:LinkButton runat="server" ID="btnSubmit" CssClass="btn btn-blue" PostBackUrl="urlhere" Text='GO <img src="/Content/img/icon-sm-arrow.png" alt="" />' />
set PostBackUrl property of Button control => https://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.button.postbackurl(v=vs.110).aspx
the reason webforms always posting it 2 itself may be due to their __doPostBack script.

Parsing information between pages in ASP

What I want to happen is when the user chooses the amount they want they click on submit. Now that amount will be passed on to the next page.
The problem is I dont understand the code in the handler, does any know a simple bit of code i can get to make this happen?
Sorry but I am not clear with asp and asp.net
Thanks
<form id='sampleform' method='post' action='handler.asp' >
<p>
Name: <input type='text' name='Name' />
</p>
<p>
Email: <input type='text' name='Email' />
</p>
<input type="radio" name="subject" value="ten" /> £10
<input type="radio" name="subject" value="five" /> £5
<input type="radio" name="subject" value="three" /> £3
£<input type='text' name='donate-amount' />
<p>
<input type='submit' name='Submit' value='Submit' />
</p>
</form>
It would help if I could see the code in handler.asp. Try the following as your handler.asp page
<%=Request.Form("Name")%> <br />
<%=Request.Form("Email")%> <br />
<%=Request.Form("subject")%> <br />
<%=Request.Form("donate-amount")%> <br />

HTML5 input type does not render correctly when publishing

I have already download and install this package to support HTML5 input type
http://support.microsoft.com/kb/2468871
The following is code in my page
<!DOCTYPE HTML>
<html>
<head runat="server">
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div>
<input id="testEmail" type="email" />
</div>
<div>
</div>
<asp:TextBox ID="testEmailAsp" runat="server" type="email"></asp:TextBox>
<asp:TextBox ID="testUrlAsp" runat="server" type="url"></asp:TextBox>
<asp:TextBox ID="textBoxTest" runat="server"></asp:TextBox>
<asp:Button ID="Button1" runat="server" Text="Button" />
</form>
</body>
</html>
This code is generated when running in visual studion 2010
<input name="testEmailAsp" type="text" id="testEmailAsp" type="email" />
<input name="testUrlAsp" type="text" id="testUrlAsp" type="url" />
<input name="textBoxTest" type="text" id="textBoxTest" />
<input type="submit" name="Button1" value="Button" id="Button1" />
When publish to the server. it renders like this.
<input name="testEmailAsp" type="text" id="testEmailAsp" type="email" />
<input name="testUrlAsp" type="text" id="testUrlAsp" type="url" />
<input name="textBoxTest" type="text" id="textBoxTest" />
<input type="submit" name="Button1" value="Button" id="Button1" />
As you can see. it render type 2 time so the markup is incorrect and that make the input type keyboard on mobile not work.
I have to install that on the server as well, i don't know that
This may sound silly but does IE9 support HTML5 input type="email", url
http://html5test.com/

Why is a postback not being triggered?

I have a simple web form, but when I submit the button postback is always false. This should all happen on the same page.
<form runat="server" class="frm" method="post" action="">
<span><input type="radio" name="options" value="Milk" /><label>Option 1</label></span>
<span><input type="radio" name="options" value="Butter" /><label>Option 2</label></span>
<span><input type="radio" name="options" value="Cheese" /><label>Option 3</label></span>
<span><input type="radio" name="options" value="Milk" /><label>Option 4</label></span>
<span><input type="radio" name="options" value="Butter" /><label>Option 5</label></span>
<span><input type="radio" name="options" value="Cheese" /><label>Option 6</label></span>
<input type="submit" name="submit" value="vote" />
</form>
*Button Code *
<asp:Button ID="loginBtn" runat="server" Text="vote" OnClick="Login" />
As Noon Silk said, you need to use server side controls, but you also need to use the asp.net mechanism on the form tag; see example code below. Notice the form tag has a 'runat="server"' attribute rather than a method and action:
<%# Page Language="C#" AutoEventWireup="true" CodeBehind="WebForm1.aspx.cs" Inherits="WebApplication1.WebForm1" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:Button ID="button" runat="server" />
</div>
</form>
</body>
</html>
Because you're not using the .net controls; you are just doing it manually.
You'd need to use an ASP.NET button, like so:
<asp:Button runat="server" ID="btnSubmit" ... />
And same for your inputs, if you want to be able to access them through txtFoo.Text. Of course, if you don't, you can still access everything through Request[...].

Resources