Hii There !! i have been in this situation i have an asp.net webpage in which i have hidden fields for payment gateway like txnid and hash value fields now when i click on my submit button it supposed to provide the txnid and hash code but its not providing anything i used to see the output by having alert boxes in asp.net but what i found is on first click of button these fields were empty and on second click of button these fields have values and everything is working fine..please help !!!
aspx code:-
<form class="RegForm" runat="server" method="post" name="Registration.aspx" id="form1" accept-charset="utf-8" >
<div id ="frmError" runat="server">
<span style="color:red">Please fill all mandatory fields.</span>
<br/>
<br/>
</div>
<!---important field dont remove -->
<input type="hidden" runat="server" id="key" name="key" />
<input type="hidden" runat="server" id="hash" name="hash" />
<input type="hidden" runat="server" id="txnid" name="txnid" />
<input type="hidden" runat="server" id="enforce_paymethod" name="enforce_paymethod" />
<!---important field dont remove --><pre></form>
.cs code
public partial class Registration : System.Web.UI.Page
{
public string action1 = string.Empty;
public string hash1 = string.Empty;
public string txnid1 = string.Empty;
public string url = string.Empty;
static string constring = ConfigurationManager.ConnectionStrings["PalpConString"].ConnectionString;
protected void Page_Load(object sender, EventArgs e)
{
try
{
key.Value = ConfigurationManager.AppSettings["MERCHANT_KEY"];
if (!IsPostBack)
{
frmError.Visible = false;
}
else
{
}
if (string.IsNullOrEmpty(Request.Form["hash"]))
{
btnSubmit.Visible = true;
}
else
{
btnSubmit.Visible = false;
}
}
catch (Exception ex)
{
Response.Write("<span style='color:red'>" + ex.Message + "</span>");
}
}
public string Generatehash512(string text)
{
byte[] message = Encoding.UTF8.GetBytes(text);
UnicodeEncoding UE = new UnicodeEncoding();
byte[] hashValue;
SHA512Managed hashString = new SHA512Managed();
string hex = "";
hashValue = hashString.ComputeHash(message);
foreach (byte x in hashValue)
{
hex += String.Format("{0:x2}", x);
}
return hex; ;
}
protected void btnSubmit_Click1(object sender, EventArgs e)
{
RecordInsertion();
try
{
string[] hashVarsSeq;
string hash_string = string.Empty;
if (string.IsNullOrEmpty(Request.Form["txnid"]))
{
Random rnd = new Random();
string strHash = Generatehash512(rnd.ToString() + DateTime.Now);
txnid1 = strHash.ToString().Substring(0, 20);
}
else
{
txnid1 = Request.Form["txnid"];
}
if (string.IsNullOrEmpty(Request.Form["hash"]))
{
if (
string.IsNullOrEmpty(ConfigurationManager.AppSettings["MERCHANT_KEY"]) ||
string.IsNullOrEmpty(txnid1) ||
string.IsNullOrEmpty(Request.Form["amount"]) ||
string.IsNullOrEmpty(Request.Form["firstname"]) ||
string.IsNullOrEmpty(Request.Form["email"]) ||
string.IsNullOrEmpty(Request.Form["phone"]) ||
string.IsNullOrEmpty(Request.Form["productinfo"]) ||
string.IsNullOrEmpty(Request.Form["surl"]) ||
string.IsNullOrEmpty(Request.Form["furl"])
)
{
frmError.Visible = true;
return;
}
else
{
frmError.Visible = false;
hashVarsSeq = ConfigurationManager.AppSettings["hashSequence"].Split('|');
hash_string = "";
foreach (string hash_var in hashVarsSeq)
{
if (hash_var == "key")
{
hash_string = hash_string + ConfigurationManager.AppSettings["MERCHANT_KEY"];
hash_string = hash_string + '|';
}
else if (hash_var == "txnid")
{
hash_string = hash_string + txnid1;
hash_string = hash_string + '|';
}
else if (hash_var == "amount")
{
hash_string = hash_string + Convert.ToDecimal(Request.Form[hash_var]).ToString("g29");
hash_string = hash_string + '|';
}
else
{
hash_string = hash_string + (Request.Form[hash_var] != null ? Request.Form[hash_var] : "");
hash_string = hash_string + '|';
}
}
hash_string += ConfigurationManager.AppSettings["SALT"];
hash1 = Generatehash512(hash_string).ToLower();
action1 = ConfigurationManager.AppSettings["PAYU_BASE_URL"] + "/_payment";
}
}
else if (!string.IsNullOrEmpty(Request.Form["hash"]))
{
hash1 = Request.Form["hash"];
action1 = ConfigurationManager.AppSettings["PAYU_BASE_URL"] + "/_payment";
}
if (!string.IsNullOrEmpty(hash1))
{
hash.Value = hash1;
txnid.Value = txnid1;
System.Collections.Hashtable data = new System.Collections.Hashtable();
data.Add("hash", hash.Value);
data.Add("txnid", txnid.Value);
data.Add("key", key.Value);
string AmountForm = Convert.ToDecimal(amount.Text.Trim()).ToString("g29");
amount.Text = AmountForm;
data.Add("amount", AmountForm);
data.Add("firstname", firstname.Text.Trim());
data.Add("email", email.Text.Trim());
data.Add("phone", phone.Text.Trim());
data.Add("productinfo", productinfo.Text.Trim());
data.Add("surl", surl.Text.Trim());
data.Add("furl", furl.Text.Trim());
data.Add("lastname", lastname.Text.Trim());
data.Add("curl", "");
data.Add("address1", address1.Text.Trim());
data.Add("address2", address2.Text.Trim());
data.Add("city", city.Text.Trim());
data.Add("state", state.Text.Trim());
data.Add("country", "");
data.Add("zipcode", zipcode.Text.Trim());
data.Add("udf1", "");
data.Add("udf2", "");
data.Add("udf3", "");
data.Add("udf4", "");
data.Add("udf5", "");
data.Add("pg", "");
data.Add("service_provider","");
string strForm = PreparePOSTForm(action1, data);
Page.Controls.Add(new LiteralControl(strForm));
}
else
{
}
}
catch (Exception ex)
{
Response.Write("<span style='color:red'>" + ex.Message + "</span>");
}
}
private string PreparePOSTForm(string url, System.Collections.Hashtable data)
{
string formID = "PostForm";
StringBuilder strForm = new StringBuilder();
strForm.Append("<form id=\"" + formID + "\" name=\"" +
formID + "\" action=\"" + url +
"\" method=\"POST\">");
foreach (System.Collections.DictionaryEntry key in data)
{
strForm.Append("<input type=\"hidden\" name=\"" + key.Key +
"\" value=\"" + key.Value + "\">");
}
strForm.Append("</form>");
StringBuilder strScript = new StringBuilder();
strScript.Append("<script language='javascript'>");
strScript.Append("var v" + formID + " = document." +
formID + ";");
strScript.Append("v" + formID + ".submit();");
strScript.Append("</script>");
return strForm.ToString() + strScript.ToString();
}
What I have tried:
i tried to have these fields inside of update panel but its again not working please help