
September 13, 2016 21:14 by
Peter
Using Command event over Click events give us better control over Coding as it provide proper manageable way to control events in a single module.

If we tend to had 5-6 button the rather than using 5-6 button click events we can use "Command" event. Multiple buttons will have same Command Event function but Multiple buttons cannot have same Click button event. each Click and Command Button are often related to a single button but always Click event will be fired firstly. "CommandName" property of each button must also be specified for each button.This property will decide
"what to do" in Command function this is common for multiple buttons.
Using Command event over Click events provide us better control over coding as it provide proper manageable way to control events in a single module.
Note:
"CommandName" property is important and required of buttons if we are using "Command" event. we can rename the Command Event function's name.
Follow this pattern,
protected void Button_Command(object sender, CommandEventArgs e)
{
switch (e.CommandName) {
case "button1":
Response.Write("Click from 1");
break;
case "button2":
Response.Write("Click from 2");
break;
case "button3":
Response.Write("Click from 3");
break;
}
}
and in aspx file,
<asp:Button ID="Button1" runat="server" Text="Button1" CommandName="button1" OnCommand="Button_Command" />
<asp:Button ID="Button2" runat="server" Text="Button2" CommandName="button2" OnCommand="Button_Command" />
<asp:Button ID="Button3" runat="server" Text="Button3" CommandName="button3" OnCommand="Button_Command" />
European best, cheap and reliable ASP.NET hosting with instant activation. HostForLIFE.eu is #1 Recommended Windows and ASP.NET hosting in European Continent. With 99.99% Uptime Guaranteed of Relibility, Stability and Performace. HostForLIFE.eu security team is constantly monitoring the entire network for unusual behaviour. We deliver hosting solution including Shared hosting, Cloud hosting, Reseller hosting, Dedicated Servers, and IT as Service for companies of all size.


September 8, 2016 20:57 by
Peter
Today, I will show you How to Post Multiple JSON Objects to Ajax Method in C#.

C# web method
[System.Web.Services.WebMethod]
public static void Post(object data, object dt)
{
List < Category > lstItems = new JavaScriptSerializer().ConvertToType < List < Category >> (data);
List < Product > lstprditems = new JavaScriptSerializer().ConvertToType < List < Product >> (dt);
string ctid = "";
string ctnme = "";
string pdid = "";
string pdnme = "";
for (int i = 0; i < lstItems.Count; i++)
{
ctid = ctid + "," + lstItems[i].categoryID;
ctnme = ctnme + "," + lstItems[i].categoryName;
}
for (int i = 0; i < lstprditems.Count; i++)
{
pdid = pdid + "," + lstprditems[i].productID;
pdnme = pdnme + "," + lstprditems[i].productName;
}
if (ctid.Length > 0)
{
ctid = ctid.Remove(0, 1);
ctnme = ctnme.Remove(0, 1);
}
if (ctid.Length > 0)
{
pdid = pdid.Remove(0, 1);
pdnme = pdnme.Remove(0, 1);
}
}
Code
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.2/jquery.min.js"></script>
<script type="text/javascript">
function PassJavascriptObject()
{
var Ct = [];
var Pd = [];
var categoryModel = {
categoryID: 1,
categoryName: "Beverage"
};
Ct.push(categoryModel);
var categoryModel1 = {
categoryID: 2,
categoryName: "Liuwu"
};
Ct.push(categoryModel1);
var productModel = {
productID: 1,
productName: "Chai"
};
Pd.push(productModel)
var productModel2 = {
productID: 2,
productName: "teccc"
};
Pd.push(productModel2)
$.ajax(
{
url: 'WebForm1.aspx/Post',
type: 'post',
dataType: 'json',
// It is important to set the content type
// request header to application/json because
// that's how the client will send the request
contentType: 'application/json',
data: JSON.stringify(
{
data: Ct,
dt: Pd
}),
cache: false,
success: function(result)
{
alert(result);
},
error: function(xhr, ajaxOptions, thrownError)
{
alert(thrownError);
}
});
}
</script>
</head>
<body>
<form id="form1" runat="server">
<div>
<span onclick="javascript:PassJavascriptObject();">Call Method</span>
</div>
</form>
</body>
</html>
European best, cheap and reliable ASP.NET hosting with instant activation. HostForLIFE.eu is #1 Recommended Windows and ASP.NET hosting in European Continent. With 99.99% Uptime Guaranteed of Relibility, Stability and Performace. HostForLIFE.eu security team is constantly monitoring the entire network for unusual behaviour. We deliver hosting solution including Shared hosting, Cloud hosting, Reseller hosting, Dedicated Servers, and IT as Service for companies of all size.


September 1, 2016 23:27 by
Peter
In this tutorial, I will show you how to Authorized.Net and PayPal Express Gateway. Now write the following code:

Default.aspx
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>
<!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 align="center">
<table style="border: 1px solid black; vertical-align: middle;" id="table3">
<tr><td colspan="2" align="center">
<asp:ValidationSummary ID="ValidationSummary1" ShowSummary="false" ShowMessageBox="true" ValidationGroup="fldGrp1" runat="server" />
</td></tr>
<tr>
<td align="right">
<asp:RequiredFieldValidator ID="RequiredFieldValidator1" ControlToValidate="ddlPaymentMethod" InitialValue="SELECT" ValidationGroup="fldGrp1" runat="server" ErrorMessage="Method is required"> * </asp:RequiredFieldValidator>Method:</td>
<td align="left"><asp:DropDownList ID="ddlPaymentMethod" onselectedindexchanged="ddlPyamentMethod_SelectedIndexChanged" AutoPostBack="true" runat="server">
<asp:ListItem>SELECT</asp:ListItem>
<asp:ListItem>American Express</asp:ListItem>
<asp:ListItem>Discover</asp:ListItem>
<asp:ListItem>Master</asp:ListItem>
<asp:ListItem>Visa</asp:ListItem>
<asp:ListItem>Paypal</asp:ListItem>
</asp:DropDownList></td>
</tr>
<tr>
<td align="right">
<asp:RequiredFieldValidator ID="RequiredFieldValidator2" ControlToValidate="txtNameOnCard" ValidationGroup="fldGrp1" runat="server" ErrorMessage="Name on card is required"> * </asp:RequiredFieldValidator>Name of the card:</td>
<td align="left"><asp:TextBox ID="txtNameOnCard" Width="250px" runat="server"></asp:TextBox></td>
</tr>
<tr>
<td align="right">
<asp:RequiredFieldValidator ID="RequiredFieldValidator3" ControlToValidate="txtCreditCardNumber" ValidationGroup="fldGrp1" runat="server" ErrorMessage="Credit card number is required"> * </asp:RequiredFieldValidator>Credit card number:</td>
<td align="left"><asp:TextBox ID="txtCreditCardNumber" Width="250px" MaxLength="20" runat="server"></asp:TextBox></td>
</tr>
<tr>
<td align="right"><asp:RequiredFieldValidator ID="RequiredFieldValidator4" ControlToValidate="ddlExpMonth" InitialValue="0" ValidationGroup="fldGrp1" runat="server" ErrorMessage="Expiration month is required"> * </asp:RequiredFieldValidator>Expiration month:</td>
<td align="left">
<asp:DropDownList ID="ddlExpMonth" runat="server">
<asp:ListItem Value="0">SELECT</asp:ListItem>
<asp:ListItem Value="1">January</asp:ListItem>
<asp:ListItem Value="2">February</asp:ListItem>
<asp:ListItem Value="3">March</asp:ListItem>
<asp:ListItem Value="4">April</asp:ListItem>
<asp:ListItem Value="5">May</asp:ListItem>
<asp:ListItem Value="6">June</asp:ListItem>
<asp:ListItem Value="7">July</asp:ListItem>
<asp:ListItem Value="8">August</asp:ListItem>
<asp:ListItem Value="9">September</asp:ListItem>
<asp:ListItem Value="10">October</asp:ListItem>
<asp:ListItem Value="11">November</asp:ListItem>
<asp:ListItem Value="12">December</asp:ListItem>
</asp:DropDownList> /<asp:RequiredFieldValidator ID="RequiredFieldValidator5" ControlToValidate="ddlExpYear" InitialValue="0" ValidationGroup="fldGrp1" runat="server" ErrorMessage="Expiration year is required"> * </asp:RequiredFieldValidator>
<asp:DropDownList ID="ddlExpYear" runat="server"></asp:DropDownList>
</td>
</tr>
<tr>
<td align="right">
<asp:RequiredFieldValidator ID="RequiredFieldValidator6" ControlToValidate="txtSecurityCode" ValidationGroup="fldGrp1" runat="server" ErrorMessage="Security code is required"> * </asp:RequiredFieldValidator>Security Code:</td>
<td align="left"><asp:TextBox ID="txtSecurityCode" Width="60px" MaxLength="5" runat="server"></asp:TextBox></td>
</tr>
<tr><td colspan="2" align="center"><asp:Label ID="lblGatewayMessage" Font-Bold="true" runat="server"></asp:Label></td></tr>
<tr><td colspan="2" align="center">
<asp:Button ID="btnChargeCard" Text="Pay-Now" OnClick="AuthorizedDotNet_Collect" ValidationGroup="fldGrp1" runat="server" />
</td></tr>
<tr><td colspan="2" align="center"> </td></tr>
</table>
</div>
</form>
</body>
</html>
Default.aspx.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using ncMerchantGateway;
public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (!Page.IsPostBack)
{
//- Let's do 10 years of credit card expiration year.
this.ddlExpYear.Items.Clear();
this.ddlExpYear.Items.Add(new ListItem("SELECT", "0"));
for (int i = 0; i <= 10; i++)
{
if (i > 0)
{
this.ddlExpYear.Items.Add(new ListItem(DateTime.Now.AddYears(i).Year.ToString(), i.ToString()));
}
}
}
}
protected void ddlPyamentMethod_SelectedIndexChanged(object sender, EventArgs e)
{
if (ddlPaymentMethod.Text.Trim().ToUpper() == "PAYPAL")
{
PayPalExpress_Collect(sender, e);
}
}
//---------------------------------------------------------------------------------
//- Warning: a merchant account from authorized.net is required.
//---------------------------------------------------------------------------------
protected void AuthorizedDotNet_Collect(object sender, EventArgs e)
{
//- Entantiate the class here
oAuthorizedotnet oGateway = new oAuthorizedotnet();
//- very important information must be entered here
oGateway.MerchantAccount_Version = "3.1"; // Authorized.net api version.
oGateway.AccountHolder_LoginId = "valid login id goes here";
oGateway.AccountHolder_TransactionKey = "valid merchant transaction key goes here";
oGateway.AccountHolder_EMail = "merchart email registered with authorized.net goes here";
oGateway.CompanyCollectorName = "ABC, Inc."; //- Merchant Company name goes here
oGateway.AuthorizeChargesOnly = true; // Authorized Only (False = {Authorized and Capture})
oGateway.Country = "USA";
oGateway.Currency = "USD";
oGateway.IsTestMode_Environment = false; //- Live
//- Amount to be charged
double dblCharges = 50.00;
//- Sales Tax if there is any based on NYC sales tax.
double dblSalesTax = (50.00 * 0.09);
//- Total to Collect
double dblTotalCharges = dblCharges + dblSalesTax;
List<string> lstCCPaymentData = new List<string>();
//- Please follow this order 0 throught 12
lstCCPaymentData.Add("Jane"); //-Billing First-Name
lstCCPaymentData.Add("Doe"); //-Billing Last-Name
lstCCPaymentData.Add("123 Apple Road"); //-Billing Address
lstCCPaymentData.Add("New York"); //-Billing City
lstCCPaymentData.Add("NY"); //-Billing State
lstCCPaymentData.Add("10040"); //-Billing Zipcode
lstCCPaymentData.Add("212-555-5555"); //-Billing Telephone
lstCCPaymentData.Add("[email protected]"); //-shipping email //-7
//- Credit card info. exactly in this order.
lstCCPaymentData.Add(this.txtCreditCardNumber.Text); //-Credit Card number
lstCCPaymentData.Add(this.ddlExpMonth.Text); //- Credit card expiration month
lstCCPaymentData.Add(this.ddlExpYear.Text); //-Credit card expiration year
lstCCPaymentData.Add(this.txtSecurityCode.Text); //-Credit card security code
lstCCPaymentData.Add(dblTotalCharges.ToString()); //-Total Amount to be either authorized or capture
//- Connect with Authorize.net gateway now.
oGateway.AuthorizeCaptureCharges(lstCCPaymentData);
//- Return Message.(Display any error message returned from the Authorized.net gateway here)
this.lblGatewayMessage.Text = oGateway.GatewayReturnedMessage.Trim();
}
//---------------------------------------------------------------------------------
//- Warning: you must have a paypal account with valid email registered.
//---------------------------------------------------------------------------------
protected void PayPalExpress_Collect(object sender, EventArgs e)
{
//- Entantiate the class here
oPayPalExpress oGateway = new oPayPalExpress();
//- very important information must be entered here
oGateway.ECommerce_SiteEMail = "[email protected]";
oGateway.ECommerce_SiteUrl = "www.johndoe.com";
oGateway.Country_Code = "US";
oGateway.Currency_Code = "USD";
oGateway.CancelledTransaction_Url = "http://www.johndoe.com/CancelledTransaction.html";
oGateway.ReturnToECommerce_SiteUrl = "http://www.johndoe.com/Thankyou.html";
//- Amount to be charged
double dblCharges = 50.00;
//- Pay Pal Fee if there is any [Warning: you must let the user know about this fee charges.]
double dblProcessingFee = (dblCharges * 2.75) / 100;
//- Sales Tax if there is any based on NYC sales tax.
double dblSalesTax = (50.00 * 0.09);
//- Total to Collect
double dblTotalCharges = dblCharges + dblSalesTax + dblProcessingFee;
List<string> lstPaymentInfo = new List<string>();
//- Please follow this order
lstPaymentInfo.Add("10012A"); //- Item Number
lstPaymentInfo.Add("Tennis Shoes Size 10"); //- Item Description
lstPaymentInfo.Add("1"); //- Qty goes here at least 1
lstPaymentInfo.Add(dblTotalCharges.ToString()); //- Amount to charge goes here
lstPaymentInfo.Add("20160813104523"); //- Invoice Number goes here
lstPaymentInfo.Add(""); //- Shipping charges if any goes here otherwise blank
lstPaymentInfo.Add(""); //- Handling charges if any goes here otherwise blank
lstPaymentInfo.Add(dblSalesTax.ToString()); //- Sales Taxes if any goes here otherwise blank
//- This part from here down is not necessary could all be blank ""
lstPaymentInfo.Add("Jane"); //- First-name
lstPaymentInfo.Add("Doe"); //- Last-name
lstPaymentInfo.Add("123 Somewhere in the city"); //- Address
lstPaymentInfo.Add("New York"); //- City
lstPaymentInfo.Add("NY"); //- State
lstPaymentInfo.Add("10005"); //- Zipcode
lstPaymentInfo.Add("212-555-5555"); //- Telephone
lstPaymentInfo.Add("[email protected]"); //- E-Mail
//- Go to paypal now and collect
oGateway.ProcessPayment(lstPaymentInfo);
}
}
European best, cheap and reliable ASP.NET hosting with instant activation. HostForLIFE.eu is #1 Recommended Windows and ASP.NET hosting in European Continent. With 99.99% Uptime Guaranteed of Relibility, Stability and Performace. HostForLIFE.eu security team is constantly monitoring the entire network for unusual behaviour. We deliver hosting solution including Shared hosting, Cloud hosting, Reseller hosting, Dedicated Servers, and IT as Service for companies of all size.


August 16, 2016 20:46 by
Peter
In this today's tutorial, I will show you how to call rest API in ASP.NET. As the Internet industry progresses, creating a REST API becomes more concrete with emerging best practices.As RESTful web services don't follow a prescribed standard except for HTTP, it's important to build your RESTful API in accordance with industry best practices to ease development and increase client adoption. A RESTful API is an application program interface (API) that uses HTTP requests to GET, PUT, POST and DELETE data.

RESTful APIs explicitly take advantage of HTTP methodologies defined by the RFC 2616 protocol. They simply use "PUT" to change the state of or update a resource, which can be an object, file or block; "GET" to retrieve a resource; POST" to create that resource; and "DELETE" to remove it.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Net;
using System.IO;
using System.Data;
using System.Data.Common;
using Golive_Web.Controller;
namespace Golive.Controller
{
public class APITEXT
{
Database database = new Database("GoliveAPI");
public DataTable GetAPI()
{
DbCommand cmd = database.GetStoredPocCommand("SP_TExt");
DataTable dtApi = database.ExecuteDataTable(cmd);
return dtApi;
}
public string GetData(String mobileNo, String ID, String APILink)
{
try
{
string XML = "<AccDtls>" + "<Request>" + "<RequestUUID>Req_" + ID + "</RequestUUID>" + "<ServiceRequestId>AcctInq</ServiceRequestId>" + "<ServiceRequestVersion>10.2</ServiceRequestVersion>" + "<ChannelId>CTS</ChannelId>" + "<AccID>" + mobileNo + "</AccID> " + "</Request>" + "</AccDtls>";
const string url = "http://100.98.2.208:6070/rbl/CTSFin";
HttpWebRequest request = (HttpWebRequest) WebRequest.Create(url);
request.ContentType = "application/xml"; //set the content type to JSON
request.Method = "POST"; //make an HTTP POST
#
region test# endregion
using(var streamWriter = new StreamWriter(request.GetRequestStream()))
{
var resToWrite = XML;
streamWriter.Write(resToWrite);
streamWriter.Flush();
streamWriter.Close();
}
// Get the response.
WebResponse response = request.GetResponse();
var streamReader = new StreamReader(response.GetResponseStream());
string result = streamReader.ReadToEnd();
return result;
}
catch (Exception)
{
throw;
}
}
}
}
European best, cheap and reliable ASP.NET hosting with instant activation. HostForLIFE.eu is #1 Recommended Windows and ASP.NET hosting in European Continent. With 99.99% Uptime Guaranteed of Relibility, Stability and Performace. HostForLIFE.eu security team is constantly monitoring the entire network for unusual behaviour. We deliver hosting solution including Shared hosting, Cloud hosting, Reseller hosting, Dedicated Servers, and IT as Service for companies of all size.


August 3, 2016 23:41 by
Peter
I am gonna explaining how to read the data from CSV file using file upload control. A CSV is a comma separated values file, which allows data to be saved in a table structured format. CSVs look like a garden-variety spreadsheet but with a .csv extension (Traditionally they take the form of a text file containing information separated by commas, hence the name). CSV files can be used with any spreadsheet program, such as Microsoft Excel, Open Office Calc, or Google Spreadsheets. They differ from other spreadsheet file types in that you can only have a single sheet in a file, they can not save cell, column, or row styling, and can not save formulas.

Code
<asp:FileUpload ID="fpContacts" runat="server" />
<asp:Button ID="btnUpload" runat="server" Text="Upload" OnClick="btnUpload_Click" /></p>
Here we need to add a new folder to the solution, why because, sometimes it will takes the fake file path. it is better to save the file and read data.
In .cs page, write the following code.
protected void btnUpload_Click(object sender, EventArgs e)
{
if (fpContacts.HasFile)
{
string spath = Server.MapPath("~/upload");
string csv_file_path = spath + "\\" + fpContacts.FileName;
fpContacts.SaveAs(csv_file_path);
DataTable csvData = GetDataTableFromCSVFile(csv_file_path);
}
}
public DataTable GetDataTableFromCSVFile(string csv_file_path)
{
DataTable csvData = new DataTable();
try
{
using (TextFieldParser csvReader = new TextFieldParser(csv_file_path))
{
csvReader.SetDelimiters(new string[] { "," });
csvReader.HasFieldsEnclosedInQuotes = true;
//read column names
string[] colFields = csvReader.ReadFields();
foreach (string column in colFields)
{
DataColumn datecolumn = new DataColumn(column);
datecolumn.AllowDBNull = true;
csvData.Columns.Add(datecolumn);
}
while (!csvReader.EndOfData)
{
string[] fieldData = csvReader.ReadFields();
ContactEntity CEntity = new ContactEntity();
B2B_BillsData BData = new B2B_BillsData();
CEntity.ContactName = fieldData[0];
CEntity.Email = fieldData[1];
CEntity.Mobile = fieldData[2];
CEntity.GroupId = ddlGroup.SelectedIndex;
CEntity.UserId = userid;
if (BData.InsertNewContact(CEntity) == true)
{
lblMsg.ForeColor = Color.Green;
lblMsg.Text = "Contact Saved successfully";
}
csvData.Rows.Add(fieldData);
}
}
}
catch (Exception ex)
{
//MessageBox.Show(ex.Message);
}
return csvData;
}
European best, cheap and reliable ASP.NET hosting with instant activation. HostForLIFE.eu is #1 Recommended Windows and ASP.NET hosting in European Continent. With 99.99% Uptime Guaranteed of Relibility, Stability and Performace. HostForLIFE.eu security team is constantly monitoring the entire network for unusual behaviour. We deliver hosting solution including Shared hosting, Cloud hosting, Reseller hosting, Dedicated Servers, and IT as Service for companies of all size.


July 27, 2016 23:06 by
Peter
Now, I will show you how to create Progress Bar In GridView with ASP.NET. The ASP.NET GridView control is the successor to the v1.x DataGrid, adding the ability to take advantage of specific capabilities of ASP.NET data source controls. Whereas the v1.x DataGrid required a page developer to write custom code to handle simple operations such as paging, sorting, editing or deleting data, the GridView control can automatically handle these operations provided its bound data source control supports these capabilities.

To make Progress Bar in GridView.
Html Code:
<div>
<asp:GridView ID="GridView1" HeaderStyle-BackColor="#3AC0F2" HeaderStyle-ForeColor="White"
runat="server" AutoGenerateColumns="false">
<Columns>
<asp:BoundField DataField="Name" HeaderText="Name" ItemStyle-Width="150" />
<asp:BoundField DataField="Percentage" HeaderText="Percentage" ItemStyle-Width="150" />
<asp:TemplateField ItemStyle-Width="300">
<ItemTemplate>
<div class='progress'>
<div class="progress-label">
<%# Eval("Percentage") %></div>
</div>
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
</div>
<style type="text/css">
.ui-progressbar
{
position: relative;
}
.progress-label
{
position: absolute;
left: 50%;
top: 4px;
font-weight: bold;
text-shadow: 1px 1px 0 #fff;
}
body
{
font-family: Arial;
font-size: 10pt;
}
</style>
<link rel="stylesheet" href="//code.jquery.com/ui/1.10.4/themes/start/jquery-ui.css">
<script type="text/javascript" src="//code.jquery.com/jquery-1.10.2.js"></script>
<script type="text/javascript" src="//code.jquery.com/ui/1.10.4/jquery-ui.js"></script>
<script type="text/javascript">
$(function () {
$(".progress").each(function () {
$(this).progressbar({
value: parseInt($(this).find('.progress-label').text())
});
});
});
</script>
Namespaces code:
using System.Data;
Code:
protected void Page_Load(object sender, EventArgs e)
{
if (!this.IsPostBack)
{
DataTable dt = new DataTable();
dt.Columns.AddRange(new DataColumn[3] { new DataColumn("Id", typeof(int)),
new DataColumn("Name", typeof(string)),
new DataColumn("Percentage",typeof(string)) });
dt.Rows.Add(1, "John Hammond", 45);
dt.Rows.Add(2, "Mudassar Khan", 37);
dt.Rows.Add(3, "Suzanne Mathews", 67);
dt.Rows.Add(4, "Robert Schidner", 12);
GridView1.DataSource = dt;
GridView1.DataBind();
}
}
European best, cheap and reliable ASP.NET hosting with instant activation. HostForLIFE.eu is #1 Recommended Windows and ASP.NET hosting in European Continent. With 99.99% Uptime Guaranteed of Relibility, Stability and Performace. HostForLIFE.eu security team is constantly monitoring the entire network for unusual behaviour. We deliver hosting solution including Shared hosting, Cloud hosting, Reseller hosting, Dedicated Servers, and IT as Service for companies of all size.


July 21, 2016 20:57 by
Peter
In this article I will show you how to use compare validator to compare the two input values. Using compare validator we can compare two values from two different input controls or we can compare input value with some constant or fixed value.

Example of compare validator:
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div>
<ul style="list-style-type: none">
<li>
<asp:TextBox ID="txt1" runat="server" />
=
<asp:TextBox ID="txt2" runat="server" />
</li>
<li>
<asp:Button ID="Button1" Text="Validate" runat="server" />
</li>
</ul>
<br>
<asp:CompareValidator ID="compareval" Display="dynamic" ControlToValidate="txt1"
ControlToCompare="txt2" ForeColor="red" Type="String" EnableClientScript="false"
Text="Values are not equal." runat="server" />
</div>
</form>
</body>
</html>
So in compare validator we need to set ControlToValidate and ControlToCompare in order to compare two input values.
European best, cheap and reliable ASP.NET hosting with instant activation. HostForLIFE.eu is #1 Recommended Windows and ASP.NET hosting in European Continent. With 99.99% Uptime Guaranteed of Relibility, Stability and Performace. HostForLIFE.eu security team is constantly monitoring the entire network for unusual behaviour. We deliver hosting solution including Shared hosting, Cloud hosting, Reseller hosting, Dedicated Servers, and IT as Service for companies of all size.


June 29, 2016 22:02 by
Peter
This time, I will show you how to generate Unique Data in GridView. This code is useful to avoiding data duplicacy in GridView:

HTML of page : EliminateGridview.aspx
<div>
<h1>
Grid with duplicate data
</h1>
<asp:GridView ID="gvDuplicate" runat="server" HeaderStyle-BackColor="gray"
AutoGenerateColumns="False" AlternatingRowStyle-BackColor="Yellow " BackColor="white"
BorderColor="blue" BorderStyle="None">
<Columns>
<asp:BoundField DataField="Name" HeaderText="Name">
<ItemStyle HorizontalAlign="Left" Width="20%" />
</asp:BoundField>
<asp:BoundField DataField="City" HeaderText="City">
<HeaderStyle Wrap="true"></HeaderStyle>
<ItemStyle HorizontalAlign="Left" Width="20%" Wrap="true" />
</asp:BoundField>
</Columns>
</asp:GridView>
</div>
<div>
<h1>
Grid with unique data
</h1>
<asp:GridView ID="gvUnique" runat="server" HeaderStyle-BackColor="gray" AutoGenerateColumns="False"
AlternatingRowStyle-BackColor="Yellow " BackColor="white" BorderColor="blue"
BorderStyle="None">
<Columns>
<asp:BoundField DataField="Name" HeaderText="Name">
<ItemStyle HorizontalAlign="Left" Width="20%" />
</asp:BoundField>
<asp:BoundField DataField="City" HeaderText="City">
<HeaderStyle Wrap="true"></HeaderStyle>
<ItemStyle HorizontalAlign="Left" Width="20%" Wrap="true" />
</asp:BoundField>
</Columns>
</asp:GridView>
</div>
Code behind page: EliminateGridview.aspx.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Configuration;
public partial class EliminateGridview: System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
gvDuplicate.DataSource = gvUnique.DataSource = testData();
gvDuplicate.DataBind();
gvUnique.DataBind();
RemoveDuplicateData(0);
}
}
//generating datatable
public DataTable testData()
{
DataTable dt = new DataTable();
//Adding columns to datatable
dt.Columns.Add("Name");
dt.Columns.Add("City");
//Adding records to the datatable
dt.Rows.Add("Peter", "London");
dt.Rows.Add("Peter", "Manchester");
dt.Rows.Add("Peter", "Liverpool");
dt.Rows.Add("Peter", "Bristol");
dt.Rows.Add("Kevin", "Leeds");
dt.Rows.Add("Kevin", "Glasgow");
dt.Rows.Add("Kevin", "York");
dt.Rows.Add("Anthony", "Cambridge");
dt.Rows.Add("Anthony", "Bradford");
dt.Rows.Add("Anthony", "Oxford");
dt.Rows.Add("Steven", "Swansea");
dt.Rows.Add("Richard", "Norwich");
return dt;
}
private void RemoveDuplicateData(int cellno)
{
string initialnamevalue = gvUnique.Rows[0].Cells[cellno].Text;
for (int i = 1; i < gvUnique.Rows.Count; i++)
{
if (gvUnique.Rows[i].Cells[cellno].Text == initialnamevalue)
{
gvUnique.Rows[i].Cells[cellno].Text = string.Empty;
}
else
{
initialnamevalue = gvUnique.Rows[i].Cells[cellno].Text;
}
}
}
}
European best, cheap and reliable ASP.NET hosting with instant activation. HostForLIFE.eu is #1 Recommended Windows and ASP.NET hosting in European Continent. With 99.99% Uptime Guaranteed of Relibility, Stability and Performace. HostForLIFE.eu security team is constantly monitoring the entire network for unusual behaviour. We deliver hosting solution including Shared hosting, Cloud hosting, Reseller hosting, Dedicated Servers, and IT as Service for companies of all size.


June 23, 2016 22:05 by
Peter
Today let me show you how to send (Pass) multiple parameters to WebMethod in jQuery AJAX POST in ASP.NET. Generally people face issues with jQuery AJAX POST call to WebMethod when multiple parameters have to be passed, due to syntax errors the WebMethod does not get called. Hence I have come up in an innovative way where using JSON object and JSON2 Stringify method one can easily post any number and any type of parameters to WebMethod using jQuery AJAX.

HTML Markup
The HTML Markup consists of a sample form with TextBoxes for accepting Name and Age and a Button to post the values to server’s WebMethod using jQuery AJAX.
<table border="0" cellpadding="0" cellspacing="0">
<tr>
<td>
Name:
</td>
<td>
<asp:TextBox ID="txtName" runat="server" Text = "Peter" />
</td>
</tr>
<tr>
<td>
Age:
</td>
<td>
<asp:TextBox ID="txtAge" runat="server" Text = "29"/>
</td>
</tr>
<tr>
<td>
<asp:Button ID="btnSubmit" Text="Submit" runat="server" />
</td>
</tr>
</table>
WebMethod accepting multiple parameters
The following WebMethod accepts multiple parameters from client side using the jQuery AJAX.
C#
[System.Web.Services.WebMethod]
public static string SendParameters(string name, int age)
{
return string.Format("Name: {0}{2}Age: {1}", name, age, Environment.NewLine);
}
VB.Net
<System.Web.Services.WebMethod()> _
Public Shared Function SendParameters(name As String, age As Integer) As String
Return String.Format("Name: {0}{2}Password: {1}", name, age, Environment.NewLine)
End Function
Passing multiple parameters to WebMethod in jQuery AJAX POST in ASP.Net
When the Button is clicked, the Name and Age is fetched from their respective TextBoxes and are assigned to a JSON object in which I have created two properties with the name same as that of the WebMethod parameters.
The JSON object is now serialized to a JSON string using JSON2 Stringify method and then passed as parameter to the WebMethod.
In this technique there are no syntax errors and also there’s no need to convert values of TextBoxes to integer or some other Data Type.
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js"></script>
<script type="text/javascript" src="http://cdnjs.cloudflare.com/ajax/libs/json2/20130526/json2.min.js"></script>
<script type="text/javascript">
$(function () {
$("[id*=btnSubmit]").click(function () {
var obj = {};
obj.name = $.trim($("[id*=txtName]").val());
obj.age = $.trim($("[id*=txtAge]").val());
$.ajax({
type: "POST",
url: "CS.aspx/SendParameters",
data: JSON.stringify(obj),
contentType: "application/json; charset=utf-8",
dataType: "json",
success: function (r) {
alert(r.d);
}
});
return false;
});
});
</script>
HostForLIFE.eu ASP.NET 4.6 Hosting
European best, cheap and reliable ASP.NET hosting with instant activation. HostForLIFE.eu is #1 Recommended Windows and ASP.NET hosting in European Continent. With 99.99% Uptime Guaranteed of Relibility, Stability and Performace. HostForLIFE.eu security team is constantly monitoring the entire network for unusual behaviour. We deliver hosting solution including Shared hosting, Cloud hosting, Reseller hosting, Dedicated Servers, and IT as Service for companies of all size.

When someone calls your company and all agents are busy assisting other customers, they will be sent to the waiting queue. When they enter the waiting queue, the "Waiting Message" plays. An example of a common Waiting Message is, "All of our agents are currently busy. Please hold and we will answer your call as soon as possible."

Sometimes we need please wait message button in our website to inform the visitor that their submission still in progress. Today, we will explain about creating please wait message in the button on ASP.NET website. You can copy below code to please wait message in the button.
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="PleaseWaitButton.aspx.cs"
Inherits="PleaseWaitButton" %>
<!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>Untitled Page</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<div>
<asp:Button ID="Button1" runat="server" Text="Button" />
</div>
</div>
</form>
</body>
</html>
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
public partial class PleaseWaitButton : System.Web.UI.Page
{
protected void Button1_Click(object sender, System.EventArgs e)
{
System.Threading.Thread.Sleep(5000);
ClientScript.RegisterClientScriptBlock(this.GetType(), "reset",
"document.getElementById('" + Button1.ClientID + "').disabled=false;", true);
}
protected void Page_Load(object sender, System.EventArgs e)
{
System.Threading.Thread.Sleep(5000);
Button1.Attributes.Add("onclick", ClientScript.GetPostBackEventReference(Button1, "") + ";
this.value='Please wait...';this.disabled = true;");
}
}
Finish, happy coding.
HostForLIFE.eu ASP.NET 4.6 Hosting
European best, cheap and reliable ASP.NET hosting with instant activation. HostForLIFE.eu is #1 Recommended Windows and ASP.NET hosting in European Continent. With 99.99% Uptime Guaranteed of Relibility, Stability and Performace. HostForLIFE.eu security team is constantly monitoring the entire network for unusual behaviour. We deliver hosting solution including Shared hosting, Cloud hosting, Reseller hosting, Dedicated Servers, and IT as Service for companies of all size.
