Create HTML table row dynamically with c# - c#

I want to add a row in HTML table with C# method, I have written the code but after execution the row appears at the top of the page not under HTML table.
<tr>
<th></th>
<th>ID</th>
<th>Date</th>
<th>Plot No.</th>
<th>Area</th>
<th>Location</th>
<th>Phase/Division</th>
<th>Remarks</th>
<th>Documents</th>
</tr>
public void AddRow() {
string html = "<tr>" +
"</td> <td class=\"text-right\"><a href = \"javascript:void(0)\" ><i class=\"fa fa-pencil\" ></i></a> </td>" +
"<td><p>1</p></td>" +
"<td><input type = \"date\" runat=\"server\" style=\"width:140px\" /></td>" +
"<td><input type =\"text\" runat=\"serve\"' style=\"width:100px\" /></td><td>" +
"<input type = \"text\" runat=\"server\" style=\"width:100px\"/></td>" +
"<td><input type = \"text\" Value=\"Test2\" runat=\"server\"/></td>" +
"<td><input type = \"text\" runat=\"server\" style=\"width:100px\"/></td>" +
"<td><input type = \"text\" runat=\"server\" style=\"height:50px\"/></td><td>" +
"<input type = \"file\" runat=\"server\" style=\"height:50px\"/></td></tr>";
Response.Write(html);
}
and calling this function from <a> tag in the table.
<td>
<a href="#" runat="server" onserverclick="Unnamed_ServerClick">
<i class="fa fa-pencil" runat="server"></i>
</a>
</td>
and it appears on the top like this.Result

Take a look on the TagBuilder:
https://learn.microsoft.com/en-us/aspnet/mvc/overview/older-versions-1/views/using-the-tagbuilder-class-to-build-html-helpers-cs

Related

Realex HPP request -custom field

I'm trying to send a custom field to realex to use upon successful response. The field in question is a json array.
[{"InvoiceId":7,"AmountPaid":180,"SucessfulPayment":false}]
The problem I face is upon response the array is truncated to [{. I have this working by base 64 encoding the array but feel its a bit heavy and would rather send the raw json. I'm also concerned there may be a character restriction on the field length's which would get eaten up quick. If there's no restriction on length I'll probably go base 64.
Update
Code as requested.
JSON array passed into request object
[{"InvoiceId":7,"AmountPaid":180,"SucessfulPayment":false}]
realex response returning
[{
Code:
<%# Page Language="C#" AutoEventWireup="true"
CodeBehind="RealexRedirectTestPay.aspx.cs"
Inherits="SmartClubOnline.RedirectTest" %>
<!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 onload="document.form.submit();">
<div class="content">
<form name="form"
action="https://hpp.sandbox.realexpayments.com/pay" method="post">
<asp:Literal ID="MERCHANT_ID" runat="server" />
<asp:Literal ID="SECRET_ID" runat="server" />
<asp:Literal ID="CLUB_NAME" runat="server" />
<asp:Literal ID="ORDER_ID" runat="server" />
<asp:Literal ID="CURRENCY_ID" runat="server" />
<asp:Literal ID="CURRENCY" runat="server" />
<asp:Literal ID="AMOUNT" runat="server" />
<asp:Literal ID="TIMESTAMP" runat="server" />
<asp:Literal ID="MEMBER_ID" runat="server" />
<asp:Literal ID="MEMBER_USERNAME" runat="server" />
<asp:Literal ID="MEMBER_EMAIL" runat="server" />
<asp:Literal ID="INVOICE_ID" runat="server" />
<asp:Literal ID="MEMBERPURSEID" runat="server" />
<asp:Literal ID="SHA1HASH" runat="server" />
<asp:Literal ID="TempOrderNumber" runat="server" />
<asp:Literal ID="PromoRow" runat="server" />
<asp:Literal ID="DELAYEDSETTLEMENTON" runat="server" />
<asp:Literal ID="CREDITCARD_SHG_AMT" runat="server" />
<asp:Literal ID="DEBITCARD_SHG_AMT" runat="server" />
<asp:Literal ID="AUTO_SETTLE_FLAG" runat="server" />
<asp:Literal ID="MERCHANT_RESPONSE_URL" runat="server" />
<!--<input type="hidden" name="AUTO_SETTLE_FLAG" value="1" />-->
<h3>
Redirecting you to our Payment Provider</h3>
<p>
You are being securely redirected to our payment provider...Please Wait...</p>
<!-- uncomment if you want the user to click a button to continue. Also remove the onload function in the Body tag -->
<!-- <p><input type="submit" name="submit" value="continue to payment provider" /></p> -->
</form>
</div>
</body>
</html>
Server side request:
MERCHANT_ID.Text = "<input type=\"hidden\" name=\"MERCHANT_ID\"
value=\"" + merchantID + "\" />";
SECRET_ID.Text = "<input type=\"hidden\" name=\"SECRET_ID\"
value=\"" + sharedSecret + "\" />";
CLUB_NAME.Text = "<input type=\"hidden\" name=\"CLUB_NAME\"
value=\"" + CLUBNAME + "\" />";
ORDER_ID.Text = "<input type=\"hidden\" name=\"ORDER_ID\"
value=\"" + orderID + "\" />";
CURRENCY.Text = "<input type=\"hidden\" name=\"CURRENCY\"
value=\"" + currencyCode + "\" />";
CURRENCY_ID.Text = "<input type=\"hidden\" name=\"CURRENCY_ID\"
value=\"" + currencyCode + "\" />";
AMOUNT.Text = "<input type=\"hidden\" name=\"AMOUNT\" value=\""
+ amount + "\" />";
TIMESTAMP.Text = "<input type=\"hidden\" name=\"TIMESTAMP\"
value=\"" + timestamp + "\" />";
MEMBER_ID.Text = "<input type=\"hidden\" name=\"MEMBER_ID\"
value=\"" + MEMBERID + "\" />";
MEMBER_USERNAME.Text = "<input type=\"hidden\"
name=\"MEMBER_USERNAME\" value=\"" + MEMBERUSERNAME + "\" />";
MEMBER_EMAIL.Text = "<input type=\"hidden\"
name=\"MEMBER_EMAIL\" value=\"" + MEMBEREMAIL + "\" />";
INVOICE_ID.Text = "<input type=\"hidden\" name=\"INVOICE_ID\"
value=\"" + INVOICEID + "\" />";
MEMBERPURSEID.Text = "<input type=\"hidden\"
name=\"MEMBERPURSEID\" value=\"" + "0" + "\" />";
SHA1HASH.Text = "<input type=\"hidden\" name=\"SHA1HASH\"
value=\"" + hash + "\" />";
AUTO_SETTLE_FLAG.Text = "<input type=\"hidden\"
name=\"AUTO_SETTLE_FLAG\" value=\"" + AUTOSETTLEFLAG + "\" />";
DELAYEDSETTLEMENTON.Text = "<input type=\"hidden\"
name=\"DELAYEDSETTLEMENTON\" value=\"" + DELAYEDSETTLEFLAG + "\" />";
CREDITCARD_SHG_AMT.Text = "<input type=\"hidden\"
name=\"CREDITCARD_SHG_AMT\" value=\"" + CREDITCARD_SHG + "\" />";
DEBITCARD_SHG_AMT.Text = "<input type=\"hidden\"
name=\"DEBITCARD_SHG_AMT\" value=\"" + DEBITCARD_SHG + "\" />";
MERCHANT_RESPONSE_URL.Text = "<input type=\"hidden\"
name=\"MERCHANT_RESPONSE_URL\" value=\"" + _realexResponseURL + "\" />";
Failing code in realex response:
if (Request.Form["INVOICE_ID"] != null)
INVOICEID = Request.Form["INVOICE_ID"].ToString();
else
StaticOps.AddErrorToLog("FORM.INVOICE_ID : ", "VALUE NULL",
"RealexResponse");
Apologies for the delay in getting back to you, didn't see the notification of your response. On the POST in, the HPP won't accept the inverted commas and truncates at that point in the string.
Could you try url encoding the string on the way out and decoding when the response comes back? The max length of a custom field on the HPP is 255. Or you could just url encode the inverted commas. Hopefully that suits your needs. Please let me know if not.
Best,
Seán MacDomhnall
Realex Payments

how to add a label text (dynamically) to a literal in code behind?

I want to add some controls to my form dynamically.
in html side:
<asp:Literal ID="Literal_news" runat="server"></asp:Literal>
my code in c# (code behind) is like below:
string str_contxt = "hi dear user!";
img2.ImageUrl = "~/images/a.jpg";
Literal_news.Text += "<article style=\"position: relative; height: 300px; opacity: 1;\"> <div class=\"banner-wrap\"> <div class=\"slider-left\"> <img src =\" " + img2.ImageUrl + " \" alt=\"\"/> </div> <div class=\"slider-left\"> <asp:Label ID=\"Label1\" runat=\"server\" Text=\" " + str_contxt + " \"></asp:Label> </div> <div class=\"clear\"></div></div></article> ";
the image is shown correct (img2.ImageUrl), but the text isn't shown(str_contxt). what is the problem ?
{I used label instead of literal control. but the problem didn't solve.}

Sending my parameters to the other side

Sorry if there are typos or inc clay error when I'm incredibly bad at English.
It is such that I need to send some value over the epay to receive my payment on my website.
onto hh.aspx looks like this:
<asp:Literal ID="LiteralDKK" runat="server"></asp:Literal>
<asp:Literal ID="LiteralPris" runat="server"></asp:Literal>
<asp:Literal ID="Literalwindowstate" runat="server"></asp:Literal>
<asp:Literal ID="LiteralOrderid" runat="server"></asp:Literal>
<asp:Literal ID="Literalmerchantnumber" runat="server"></asp:Literal>
on hh.aspx.cs
string dkk = "DKK";
string windowstate = "3";
string merchantnumber = "1111111";
string prisen = "10";
string ordernr = "159sg";
LiteralDKK.Text = "<input id=\"HiddenPris\" type=\"hidden\" name=\"currency\" value=\"" + dkk + "\" />";
Literalmerchantnumber.Text = "<input id=\"Hiddenmerchantnumber\" type=\"hidden\" name=\"merchantnumber\" value=\"" + merchantnumber + "\" />";
Literalwindowstate.Text = "<input id=\"Hiddenwindowstate\" type=\"hidden\" name=\"windowstate\" value=\"" + windowstate + "\" />";
LiteralPris.Text = "<input id=\"HiddenPris\" type=\"hidden\" name=\"amount\" value=\"" + prisen + "\" />";
LiteralOrderid.Text = "<input id=\"HiddenOrderid\" type=\"hidden\" name=\"orderid\" value=\"" + ordernr + "\" />";
//It must send my value onto this here page
Response.Redirect("https://ssl.ditonlinebetalingssystem.dk/integration/ewindow/Default.aspx");
My parameters which I would like to have sent to you can see how to appear here
If I had to do it in html, it looked like this,
<form action="https://ssl.ditonlinebetalingssystem.dk/integration/ewindow/Default.aspx" method="post">
<input name="merchantnumber" value="ENTER YOUR MERCHANT NUMBER HERE">
<input name="amount" value="10495"> <input name="currency" value="DKK">
<input name="windowstate" value="3"> <input type="submit" value=
"Go to payment">
</form>
The reason I do not do it is to secure me the right price and ordernr and many other things which must cross in.
The documentation here seems to provide simple ways to do this:
http://tech.epay.dk/da/betalingsvindue-integration
In English:
http://tech.epay.dk/en/payment-window-integration

posting data from a razor generated table

I have a table filled with generated data using razor. Each row has the id of the PlanID in the database.
<tbody>
#foreach(var plan in ViewBag.plans) {
<tr id="#plan.PlanID">
<td contenteditable="true">#plan.Name</td>
<td contenteditable="true">#plan.Code</td>
<td contenteditable="true">#plan.Description</td>
<td contenteditable="true">#plan.DataAmount</td>
<td contenteditable="true">#plan.Price</td>
<td contenteditable="true">#plan.SmartPhoneCost</td>
<td><a><span class="glyphicon glyphicon-pencil"></span></a></td>
</tr>
}
</tbody>
I have also made button click append the table with a new row to add a plan
function Add() {
$("#tableData tbody").append(
"<tr role='form' action='/api/wirelessplans' method='post'>" +
"<td><input name='Name' type='text' size='30' maxlength='30'/></td>" +
"<td><input name='Code' type='text' /></td>" +
"<td><input name='Description' type='text' size='50' maxlength='50'/></td>" +
"<td><input name='DataAmount' type='text' /></td>" +
"<td><input name='Price' type='text' /></td>" +
"<td><input name='SmartPhoneCost' type='text' /></td>" +
"<td><a class='save' type='submit'><span class='glyphicon glyphicon-ok'></span></a></td>" +
"</tr>")
};
$(function () {
$("body").on("click", ".addPlan", function () {
Add()
});
});
I have made the the td's editable and would like to click on the icon to submit the changes to -- api/wirelessplans/ that I defined in my controller. How do I grab only the values that are changed (or added in the new row) and post/put to the database?

How to read JSON and Display in html table in c#?

I have following JSON:
{"ios_info":{"serialNumber":"F2LLMBNJFFFQ1","imeiNumber":"0138840041323551","meid":"","iccID":"89014104276400960452","firstUnbrickDate":"11\/27\/13","lastUnbrickDate":"11\/27\/13","unbricked":"true","unlocked":"false","productVersion":"7.1.2","initialActivationPolicyID":"23","initialActivationPolicyDetails":"US AT&T Puerto Rico and US Virgin Islands Activation Policy","appliedActivationPolicyID":"23","appliedActivationDetails":"US AT&T Puerto Rico and US Virgin Islands Activation Policy","nextTetherPolicyID":"23","nextTetherPolicyDetails":"US AT&T Puerto Rico and US Virgin Islands Activation Policy","macAddress":"ACFDEC6C988A","bluetoothMacAddress":"AC:FD:EC:6C:98:8B","partDescription":"IPHONE 5S SPACE GRAY 64GB-USA"},"fmi":{"#attributes":{"version":"1","deviceCount":"1"},"fmipLockStatusDevice":{"#attributes":{"serial":"F2LLMBNJFFFQ","imei":"013884004132355","isLocked":"true","isLost":"false"}}},"product_info":{"serialNumber":"F2LLMBNJFFFQ1","warrantyStatus":"Apple Limited Warranty","coverageEndDate":"11\/25\/14","coverageStartDate":"11\/26\/13","daysRemaining":"497","estimatedPurchaseDate":"11\/26\/13","purchaseCountry":"United States","registrationDate":"11\/26\/13","imageURL":"http:\/\/service.info.apple.com\/parts\/service_parts\/na.gif","explodedViewURL":"http:\/\/service.info.apple.com\/manuals-ssol.html","manualURL":"http:\/\/service.info.apple.com\/manuals-ssol.html","productDescription":"iPhone 5S","configDescription":"IPHONE 5S GRAY 64GB GSM","slaGroupDescription":"","contractCoverageEndDate":"11\/25\/15","contractCoverageStartDate":"11\/26\/13","contractType":"C1","laborCovered":"Y","limitedWarranty":"Y","partCovered":"Y","notes":"Covered by AppleCare+ - Incidents Available","acPlusFlag":"Y","consumerLawInfo":{"serviceType":"","popMandatory":"","allowedPartType":""}}}
Reading JSON string:
private string GetKeyValuePairs(string jsonString)
{
rowcnt++;
var resDict = JsonConvert.DeserializeObject<Dictionary<string, object>>(jsonString);
string sdict = string.Empty;/*#"<table id='tblAppleResult' cellspacing='0' cellpadding='3' border='1' style='width: 100%; border-collapse: collapse;'>
<tr>
<td>
</td>
<td>
</td>
</tr>";*/
foreach (string key in resDict.Keys)
{
sdict += "<br/> " + key + " : " + (resDict[key].GetType() == typeof(Newtonsoft.Json.Linq.JObject) ? GetKeyValuePairs(resDict[key].ToString()) : resDict[key].ToString());
//sdict += "<tr><td> " + key + "</td> " + (resDict[key].GetType() == typeof(Newtonsoft.Json.Linq.JObject) ? "<td>" + GetKeyValuePairs(resDict[key].ToString()) + "</td></tr>" : "<td>" + resDict[key].ToString() + "</td></tr>");
}
//sdict += "</table>";
return sdict;
}
This displays the Data. But i want in HTML Table Format.(independent of inner Keys. i mean every row will began in new as per commented above.
Problem:
As its recursive it goes on displaying table into another table. i.e for child attributes with other child attributes.
I need the output just in TWO COLUMNS ONLY with Key:Value as output.
Here is the solution:
string tbl = #"<table id='tblAppleResult' cellspacing='0' cellpadding='3' border='1' style='width: 100%; border-collapse: collapse;'><tr>
<td>
</td>
<td>
</td>
</tr>";
lblkeyValue.Text = tbl+GetKeyValuePairs(responseText)+"</table>";

Categories