When I use the following: <asp:TextBox ID="x_zip" runat="server"></asp:TextBox>
My value shows up here: ctl00$MainContent$x_zip
But when I use: <input id="x_zip" type="text" />
My value shows up properly here: x_zip
My question is, is it possible to use a textbox instead of a basic html input field to post to x_... fields? If so, can you provide sample code for both the .aspx and code behind pages (including where the code is place, pageload, button click event, etc.)?
The main reason I want to stick to the asp textboxes is for data validation purposes. Is there good reason I shouldn't use a textbox and should stick to the html input fields?
12-02-2011 03:14 PM
If you are on framework 4.0. You should be able to set the ClientIDMode="Static" on the textbox.
12-02-2011 03:48 PM
I'm in ASP.NET 4.0 and setting the clientID to static didn't change anything. Here's a test of me trying to use a textbox to insert the zip into x_zip.
Here is a simplified version of my aspx code
<%@ Page Title="Store" Language="C#" AutoEventWireup="false" CodeFile="Store_SIM_TXBX.aspx.cs" MasterPageFile="~/MasterPages/Site.master" Inherits="Confirm" ViewStateMode="Disabled" %> <asp:Content ID="HeaderContent" runat="server" ContentPlaceHolderID="HeadContent"> </asp:Content> <asp:Content ID="BodyContent" runat="server" ContentPlaceHolderID="MainContent"> <div> <br /> <br /> Zip: <asp:TextBox ID="x_zip" runat="server" ClientIDMode="Static"></asp:TextBox> <div style="text-align: center;"> <asp:Button ID="btnSubmit" runat="server" Text="Complete the Purchase" ClientIDMode="Static" CssClass="button" /> </div> </div> </asp:Content>
And simplified Code Behind
using Microsoft.VisualBasic; using System; using System.Collections; using System.Collections.Generic; using System.Data; using System.Diagnostics; using System.Configuration; using System.Web.Security; using System.Web.UI.WebControls; using System.Data.SqlClient; partial class Confirm : System.Web.UI.Page { protected void Page_Load(object sender, System.EventArgs e) { btnSubmit.PostBackUrl = "https://developer.authorize.net/tools/paramdump/index.php";//shows fields submitted strAuthorizeNet_x_amount = "99.99"; strAuthorizeNet_x_login = ConfigurationManager.AppSettings.Get("AUTHORIZE_NET_API_LOGIN"); strAuthorizeNet_x_fp_timestamp = AuthorizeNet.Crypto.GenerateTimestamp().ToString(); strAuthorizeNet_x_test_request = "TRUE";//does not show in unsettled } private string strAuthorizeNet_x_fp_timestamp; public string AuthorizeNet_x_fp_timestamp { get { return strAuthorizeNet_x_fp_timestamp; } } private string strAuthorizeNet_x_login; public string AuthorizeNet_x_login { get { return strAuthorizeNet_x_login; } } private string strAuthorizeNet_x_test_request; public string AuthorizeNet_x_test_request { get { return strAuthorizeNet_x_test_request; } } private string strAuthorizeNet_x_amount; public string AuthorizeNet_x_amount { get { return strAuthorizeNet_x_amount; } } public string CardNumber { get { if (strAuthorizeNet_x_test_request.Equals("TRUE")) { return "4111111111111111"; } return ""; } } public string ExpirationDate { get { if (strAuthorizeNet_x_test_request.Equals("TRUE")) { return DateTime.Now.AddMonths(1).ToString("MM-yy"); } return ""; } } public string CCV { get { if (strAuthorizeNet_x_test_request.Equals("TRUE")) { return "123"; } return ""; } } public Confirm() { Load += Page_Load; } }
and the results
Field Name Field Value __EVENTTARGET ctl00$MainContent$x_zip 90210 ctl00$MainContent$btnSubmit Complete the Purchase __VIEWSTATE /wEPDwUKMTUyMDk1... __EVENTARGUMENT __EVENTVALIDATION /wEWBALz78Ax... __PREVIOUSPAGE RsRhW_on3HU...
12-02-2011 04:18 PM
It is modify from SIM sample code.
It going to be something like this on the aspx page
<asp:Content ID="BodyContent" ContentPlaceHolderID="MainContent" runat="server"> <input type='hidden' name='x_login' id='x_login' value='<%=x_login%>' /> <input type='hidden' runat="server" name='x_amount' id='x_amount' value='<%=x_amount%>' /> <input type='hidden' runat="server" name='x_description' id='x_description' value='<%=x_description%>' /> <input type='hidden' runat="server" name='x_invoice_num' id='x_invoice_num' value='<%=x_invoice_num%>' /> <input type='hidden' runat="server" name='x_fp_sequence' id='x_fp_sequence' value='<%=x_fp_sequence%>' /> <input type='hidden' runat="server" name='x_fp_timestamp' id='x_fp_timestamp' value='<%=x_fp_timestamp%>' /> <input type='hidden' runat="server" name='x_fp_hash' id='x_fp_hash' value='<%=x_fp_hash%>' /> <input type='hidden' name='x_show_form' value='PAYMENT_FORM' /> <input type='hidden' name='x_relay_response' value='TRUE' /> <asp:Button ID="btnSubmit" runat="server" Text="Complete the Purchase" ClientIDMode="Static"
CssClass="button" /> </asp:Content>
Notice that it set the value like value='<%=x_fp_hash%>'
Then, on the codebehind
private string p_x_login;
protected string x_login
{
get { return p_x_login; }
set { p_x_login = value; }
}
This is the property for x_login input value='<%=x_login%>', and do it for the rest of the fields.
and on the page_load
x_login = "10charcode";
12-02-2011 05:17 PM - edited 12-02-2011 05:18 PM