Pages

Subscribe:

Ads 468x60px

Wednesday, April 18, 2012

How to sum the value of gridview column in asp.net using jquery and c#

In this web programming tutorial we will learn that how we can SUM the grid view columns values in asp.net using c#.
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default2.aspx.cs" Inherits="Default2" %>




    
    
    


    
Code for .cs file
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class Default2 : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        grdItems.DataSource = new Item().Items;
        grdItems.DataBind();

    }

}
public class Item
{
    public string Name { get; set; }
    public int Quantity { get; set; }
    public decimal Price { get; set; }

    public List Items
    {
        get
        {
            return new List()
                       {
                           new Item(){Name = "Item01",Quantity = 10,Price = 180M},
                           new Item(){Name = "Item01",Quantity = 11,Price = 184M},
                           new Item(){Name = "Item01",Quantity = 12,Price = 190M},
                           new Item(){Name = "Item01",Quantity = 13,Price = 110M},
                       };
        }
    }
}

how to re-write url in asp.net using c#

In this web programming tutorial we will learn that how we can re-write url in asp.net, as it is very important and common and most difficult task for an asp.net developer to re-write url. For URL Rewriting we are using URLRewriter.Net which is available free. Download URLRewriter.Net
Step 1: Download Binary Files for URLRewriter.Net
Step 2: Add Reference to Binary Files, Right click project "Add Reference" and add binary files.
Step 3: Update Web.Config File to make URLRewriter.Net works.


Step 4: Adding Function to Generate SEO Friendly URL from given Title
public static string GenerateURL(object Title, object strId)
{
string strTitle = Title.ToString();

#region Generate SEO Friendly URL based on Title
//Trim Start and End Spaces.
strTitle = strTitle.Trim();

//Trim "-" Hyphen
strTitle = strTitle.Trim('-');

strTitle = strTitle.ToLower();
char[] chars = @"$%#@!*?;:~`+=()[]{}|\'<>,/^&"".".ToCharArray();
strTitle = strTitle.Replace("c#", "C-Sharp");
strTitle = strTitle.Replace("vb.net", "VB-Net");
strTitle = strTitle.Replace("asp.net", "Asp-Net");

//Replace . with - hyphen
strTitle = strTitle.Replace(".", "-");

//Replace Special-Characters
for (int i = 0; i < chars.Length; i++)
{
string strChar = chars.GetValue(i).ToString();
if (strTitle.Contains(strChar))
{
   strTitle = strTitle.Replace(strChar, string.Empty);
}
}

//Replace all spaces with one "-" hyphen
strTitle = strTitle.Replace(" ", "-");

//Replace multiple "-" hyphen with single "-" hyphen.
strTitle = strTitle.Replace("--", "-");
strTitle = strTitle.Replace("---", "-");
strTitle = strTitle.Replace("----", "-");
strTitle = strTitle.Replace("-----", "-");
strTitle = strTitle.Replace("----", "-");
strTitle = strTitle.Replace("---", "-");
strTitle = strTitle.Replace("--", "-");

//Run the code again...
//Trim Start and End Spaces.
strTitle = strTitle.Trim();

//Trim "-" Hyphen
strTitle = strTitle.Trim('-');
#endregion

//Append ID at the end of SEO Friendly URL
strTitle = "~/Article/" + strTitle + "-" + strId + ".aspx";

return strTitle;
}

Step 5: Changing DataBinder.Eval Function in .Aspx Page to reflect changes in URL of Grid.



   
       
                      
       
   
   
       
           
       
   









how to Send Email from Gmail in asp.net using c#

In this web programming tutorial we will learn that how we can send email from Gmail in asp.net using c#, see the below code and just copy and paste.

protected void btnSendEmail_Click(object sender, EventArgs e)
{
//Create Mail Message Object with content that you want to send with mail.
System.Net.Mail.MailMessage MyMailMessage = new System.Net.Mail.MailMessage("faisalpitafi@gmail.com","israrpatafi@yahoo.com",
"This is the mail subject", "Just wanted to say Hello");

MyMailMessage.IsBodyHtml = false;

//Proper Authentication Details need to be passed when sending email from gmail
System.Net.NetworkCredential mailAuthentication = new
System.Net.NetworkCredential("irfanpitafi@gmail.com", "myPassword");

//Smtp Mail server of Gmail is "smpt.gmail.com" and it uses port no. 587
//For different server like yahoo this details changes and you can
//get it from respective server.
System.Net.Mail.SmtpClient mailClient = new System.Net.Mail.SmtpClient("smtp.gmail.com",587);

//Enable SSL
mailClient.EnableSsl = true;

mailClient.UseDefaultCredentials = false;

mailClient.Credentials = mailAuthentication;

mailClient.Send(MyMailMessage);
}

how to Disable Multiple Button Click in Asp.net using jquery, javascript and c#

In this web programming tutorial we will learn that How to make a button disable immediately when user clicks it in asp.net so that user cannot click multiple time.




Code for body section


Note: onclick event is calling javascript client-side function and onserverclick event is calling server-side function which performs actual task.
This task can be any as per your logic, for an example I am performing some heavy time consuming task, you can even make use of Threading concept to minimize code.
Server-Side Event to perform actual task
protected void Button1_Click(object sender, EventArgs e)
{
ArrayList a = new ArrayList();
for (int i = 0; i < 10000; i++)
{
for (int j = 0; j < 1000; j++)
{
a.Add(i.ToString() + j.ToString());
}
}
Response.Write("I am done: " +
DateTime.Now.ToLongTimeString());
}

How to enable/disable dropdownlist combobox through a checkbox selection in asp.net using jquery

In this web programming tutorial we will learn that how we can enable/disable dropdownlist control through checkbox selection in asp.net.



    
    
    


    


How to Add copy to clipboard button on page

In this web programming tutorial we will learn how to add or PUT add copy to clip board button functionality on your html or asp.net page copy the below code in your html page.




    

Thursday, April 12, 2012

how to get IP address of visitor using php

In this web programming tutorial we will learn that how we can get or track real (orignal) IP address of visitor of our page.
return !empty($_SERVER['HTTP_CLIENT_IP']) ?
$_SERVER['HTTP_CLIENT_IP'] : (!empty($_SERVER['HTTP_X_FORWARDED_FOR']) ?
$_SERVER['HTTP_X_FORWARDED_FOR'] : (!empty($_SERVER['REMOTE_ADDR']) ?
$_SERVER['REMOTE_ADDR'] : null));

Wednesday, April 11, 2012

how to access web method or server side data at client side in asp.net using c#

In this web programming tutorial we will learn that how we can access server side data using Json ajax call at client side using asp.net or php. see the below code and just copy and past in your .aspx or .php file.
function BindPaymentRecord(txnId) { var request = "{'TXN_ID':'" + txnId + "'}"; $.ajax({ type: "POST", url: "Invoice.aspx/BindPaymentDetail", data: request, contentType: "application/json; charset=utf-8", dataType: "json", success: SuccessPaymentRecord }); } function BindChargesRecord(txnId) { var request = "{'TXN_ID':'" + txnId + "'}"; $.ajax({ type: "POST", url: "Invoice.aspx/BindChargesDetail", data: request, contentType: "application/json; charset=utf-8", dataType: "json", success: ChargesSuccessData }); } function SuccessPaymentRecord(data) { document.getElementById('<%=A_Paid.ClientID %>').innerHTML = data.d[0]; document.getElementById('<%=C_ref.ClientID %>').innerHTML = data.d[1]; document.getElementById('<%=C_Bal.ClientID %>').innerHTML = data.d[2]; document.getElementById('<%=Error.ClientID %>').innerHTML = data.d[3]; document.getElementById('<%=P_Method.ClientID %>').innerHTML = data.d[4]; document.getElementById('<%=P_date.ClientID %>').innerHTML = data.d[5]; }

how to generate barcode in asp.net using c#

In this web programming tutorial we will learn that how we can generate barcode in asp.net using c#, as it is often used in different projects and web developers have to face problem, see the below code and just copy and past in your page.
Code for .CS file

using System;
using System.Data;
using System.Drawing.Imaging;
using System.Configuration;
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;

using Bytescout.BarCode;

public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
// Create new barcode
Barcode barcode = new Barcode();

// Set symbology
barcode.Symbology = SymbologyType.Code39;
// Set value
barcode.Value = "Sample";

// Clear http output
Response.Clear();
// Set the content type to PNG
Response.ContentType = "image/png";
// Add content type header
Response.AddHeader("Content-Type", "image/png");
// Set the content disposition
Response.AddHeader("Content-Disposition", "inline;filename=result.png");

// Save image to output stream
barcode.SaveImage(Response.OutputStream, ImageFormat.Png);

// End response
Response.End();

}
}

how to Writing a Text Files Line Counter in asp.net using c#

In this web programming tutorial we will learn that how we can Writing a Text Files Line Counter in asp.net using c#, Bellow is the code, it's so simple that I'm lazy to explain, enjoy:
DirectoryInfo dInfo = new DirectoryInfo(args[0]);
FileInfo[] Files = dInfo.GetFiles("*.php");
int i = 0;
foreach (FileInfo fInfo in Files)
{
  string[] temp = File.ReadAllLines(fInfo.FullName);
  i += temp.Length;
}
Console.WriteLine("Total Lines: " + i);
Console.ReadLine();