Friday, February 22, 2013

paypal integration by c#


code behind
==========================

  string strPostURL = string.Empty;
        if (ConfigurationManager.AppSettings["IsLive"].ToLower() == "L".ToLower())
        {
            strPostURL = ConstantValue.Liveurl;
        }
        else
        {
            strPostURL = ConstantValue.TestUrl;
        }
        PayPalTran obj = new PayPalTran();
        Hashtable hs = new Hashtable();
        hs = obj.GetHashTableForPaypal();
        //Add parameters on from
        HtmlInputHidden hiddenInputControl = new HtmlInputHidden();
        System.Web.UI.HtmlControls.HtmlForm oForm = new System.Web.UI.HtmlControls.HtmlForm();
        oForm.Attributes.Add("action", strPostURL);
        oForm.Attributes.Add("method", "post");
        IDictionaryEnumerator en = hs.GetEnumerator();
        while (en.MoveNext())
        {
            hiddenInputControl = new HtmlInputHidden();
            hiddenInputControl.Name = en.Key.ToString();
            hiddenInputControl.ID = en.Key.ToString();
            hiddenInputControl.Value = en.Value.ToString();
            oForm.Controls.Add(hiddenInputControl);
          
        }
        hiddenInputControl = new HtmlInputHidden();
        hiddenInputControl.Name = "notify_url";
        hiddenInputControl.ID = "notify_url";
        hiddenInputControl.Value = clsComman.SecureUrl + "PayPalno_url.aspx";
        oForm.Controls.Add(hiddenInputControl);
        bodydPay.Controls.Add(oForm);
       

        if (Session["PTran"] != null)
        {
            Page.RegisterStartupScript("a0", Session["PTran"].ToString());
        }
        Page.RegisterStartupScript("a1", "<script>document.forms[0].action = '" + strPostURL + "';</script>");
        Page.RegisterStartupScript("a2", "<script>document.forms[0].submit();</script>");
    }
}

+++++++++++++++++

aspx page
 <%@ Page Language="C#" AutoEventWireup="true" CodeFile="PayPal.aspx.cs" Inherits="PayPalPost" %>
<!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> CheckOut</title>
    <style type="text/css">
     body
{
    font-family: Arial, Helvetica, sans-serif;
    font-size: 14px;
    color: #111B07;
  
    margin: 0 auto;
  
}
    </style>
  
</head>
<body id="bodydPay" runat="server">
    <div style="width: 100%; height: 100%; text-align: center;">
        <br />
        <br />
        <br />
        <br />
        <br />
        <br />
        <br />
        <br />
        <br />
        <img src="Images/Load.gif" />
        <p style="color: green;">
            <b>You are redirecting to the PayPal.....</b></p>
        <p style="color: Red;">
            <b>PayPal can take some time, please be patient while your contract goes through.</b></p>
    </div>
</body>
</html>
 

Thursday, February 21, 2013

how to print and automaticay close windows in asp.net c#

in head section
=============

<script type="text/javascript" language="javascript">
function PrintControl() {
window.print();
 window.onfocus = function () { window.close(); }
}
</script>

=================
in asp.net .cs page
Page.ClientScript.RegisterStartupScript(GetType(), "MyKey", "PrintControl();", true);

How to Fetch data from database using jquery c#

product.js
===================
$(document).ready(function () {
    $.ajax({
        type: "POST",
        url: "productget.aspx/binddata",
        data: {},
        contentType: "application/json; charset=utf-8",
        dataType: "json",
        success: function (data) {
            for (var i = 0; i < data.d.length; i++) {
                $("#dresult").append("<tr><td><input id=txtname type=text value=" + (data.d[i].id) + "></td><td>" + (data.d[i].name) + "</td><td>" + (data.d[i].age) + "</td><td><input type=button value=Submit /></td></tr>");
            }
        }
    });
});
====================
productget.aspx(For Fetch data from  aspx.cs with  database or self table)
====================
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.Web.Services;
public partial class productget : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        { }
    }
    public class Details
    {
        public int id { get; set; }
        public string name { get; set; }
        public int age { get; set; }
    }
    [WebMethod]
    public static Details[] binddata()
    {
        DataTable dtt = new DataTable("Table");
        dtt.Columns.Add(new DataColumn("id", Type.GetType("System.Int32")));
        dtt.Columns.Add(new DataColumn("name", Type.GetType("System.String")));
        dtt.Columns.Add(new DataColumn("age", Type.GetType("System.Int32")));
        dtt.Rows.Add(1, "A", 12);
        dtt.Rows.Add(2, "B", 11);
        dtt.Rows.Add(3, "C", 10);
        dtt.Rows.Add(4, "D", 09);
        List<Details> detail = new List<Details>();
//here You can  used  database
//==========
        foreach (DataRow dt_row in dtt.Rows)
        {
            Details usr = new Details();
            usr.id = Convert.ToInt32(dt_row["id"]);
            usr.name = dt_row["name"].ToString();
            usr.age = Convert.ToInt32(dt_row["age"]);
            detail.Add(usr);
        }
        return detail.ToArray();
    }
}
===============================

USR UI (productdetails.aspx)


<%@ Page Language="C#" AutoEventWireup="true" CodeFile="productdetails.aspx.cs" Inherits="productdetails" %>
<!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>     
        <script src="Script/jquery-1.4.1.min.js" type="text/javascript" ></script>
        <script src="Script/product.js" type="text/javascript" ></script>
      
</head>
<body >
    <form id="form1" runat="server">
    <div>
<span class="result" id="dresult" runat="server"></span>
  </div>
    </div>
    </form>
</body>
</html>
 

Monday, February 18, 2013

Other Blog

ClientIdMode Property

Accessing the control's id at runtime, when the page being used is the master page, has been a persistent issue, especially when we are trying to access the control's id(Client Id) using JavaScript.
There are four types of ClientIDMode

 
1. AutoID
2. Static
3. Predictable
4. Inherit


1. AutoID

This is the existing behavior as in ASP.NET 1.x-3.x.

<asp:Content ID="HeaderContent" runat="server" ContentPlaceHolderID="HeadContent">
    <script type="text/javascript" language="javascript">
        function ClientIdExample() {
           
var id = document.getElementById('<%=txtMinfire.ClientID%>');
            alert(id);
        }
        window.onload = ClientIdExample
    </script>
</asp:Content>

 

<asp:Content ID="BodyContent" runat="server" ContentPlaceHolderID="MainContent">
    <div id="divMindfire">
        <asp:TextBox ID="txtMinfire" ClientIDMode="AutoID" Text="Proud to be Mindfireans"
            runat="server" />
    </div>
</asp:Content> 
After Page Renders

<input name="ctl00$MainContent$txtMinfire" type="text" value="Proud to be Mindfireans" id="ctl00_MainContent_txtMinfire" />
 
 
2. Static

This option forces the control’s ClientID to use its ID value directly.This is most commonly used but the major drawback is with same control with multiple instances(like multiple instances of a usercontrol).If there are several instances of the same naming container so client ID naming conflict.
 
<asp:Content ID="HeaderContent" runat="server" ContentPlaceHolderID="HeadContent">
    <script type="text/javascript" language="javascript">
        function ClientIdExample() {
            var id = document.getElementById('txtMinfire');
            alert(id);
        }
        window.onload = ClientIdExample
    </script>
</asp:Content>
<asp:Content ID="BodyContent" runat="server" ContentPlaceHolderID="MainContent">
    <div id="divMindfire">
        <asp:TextBox ID="txtMinfire" ClientIDMode="Static" Text="Proud to be Mindfireans"
            runat="server" />
    </div>
</asp:Content>
 
3.Inherit
 
By default all the control's ClientIDMode is Inherit,it only places the inherited control id for each controls within the masterpage
 
<asp:Content ID="HeaderContent" runat="server" ContentPlaceHolderID="HeadContent">
    <script type="text/javascript" language="javascript">
        function ClientIdExample() {
            var id = document.getElementById('MainContent_txtMinfire'); // ContentPlaceHolderID_IDOfTheControl
            alert(id);
        }
        window.onload = ClientIdExample
    </script>
</asp:Content>
<asp:Content ID="BodyContent" runat="server" ContentPlaceHolderID="MainContent">
    <div id="divMindfire">
        <asp:TextBox ID="txtMinfire" ClientIDMode="Inherit" Text="Proud to be Mindfireans"
            runat="server" />
    </div>
</asp:Content>
 
After Page Renders
 <input name="ctl00$MainContent$txtMinfire" type="text" value="Proud to be Mindfireans" id="MainContent_txtMinfire" />
 
 
4. Predictable
 
Predictable is the important mode of the Client ID Mode and it is mainly used for controls that are in data-bound controls.We can generate the ClientID value by concatenating the ClientID value of the parent naming container with the ID value of the current control.ClientIDRowSuffix is a property of the control which can be added at the end of a databound control that generates the multiple rows.Best example is the GridView Control where multiple data fileds can be specified and if the ClientIDRowSuffix property is blank then it will automatically add a sequential number at the end of the databound control id.This number begins at zero and is incremented by 1 for each row and each segment is separated by an underscore character (_).
 
Given below examples demonstrate how the databound control id renders in both the case(without ClientIDRowSuffix and with ClientIDRowSuffix )
 
<asp:GridView ID="gvMindfire" runat="server" AutoGenerateColumns="false" ClientIDMode="Predictable" >
    <Columns>
        <asp:TemplateField HeaderText="ID">
            <ItemTemplate>
         <asp:Label ID="lblID" runat="server" Text='<%# Eval("ID") %>' />
            </ItemTemplate>
        </asp:TemplateField>
        <asp:TemplateField HeaderText="Name">
            <ItemTemplate>
      <asp:Label ID="lblName" runat="server" Text='<%# Eval("Name") %>' />
            </ItemTemplate>
        </asp:TemplateField>
        <asp:TemplateField HeaderText="Company Name">
            <ItemTemplate>
                <asp:Label ID="lblOrganisation" runat="server" Text='<%# Eval("CompName") %>' />
            </ItemTemplate>
        </asp:TemplateField>
    </Columns>
</asp:GridView>
 
 
You can set ClientIDMode property in 3 ways

1.Application Level
2.Page Level
3.Control Level
 
Setting ClientIDMode at Application Level
You need to set it at System.Web section of Web.config


<system.web>
<pages clientIDMode="Static">
</pages> 
</system.web>
 
Setting ClientIDMode at Page Level

<%@ Page Language="C#" ClientIDMode ="Inherit" AutoEventWireup="true" CodeBehind="Mindfire.aspx.cs" Inherits="Mindfire" %>

 
Setting ClientIDMode at Control Level

Each and every server control in ASP.NET 4.0 has this property and the default value is inherit.

<asp:TestBox id="txtMindfire" runat="server" ClientIDMode ="Static"> </asp:TextBox>

Friday, February 8, 2013

How to make sitemap and breadcumb?

public static void Createsitemap(string path)



{

XmlDocument xmldoc = new XmlDocument();

System.Text.StringBuilder sp = new System.Text.StringBuilder();

sp.Append("<?xml version='1.0' encoding='utf-8'?>");

string defaultURL = "Home";

string defaultTitle = "Home";

sp.Append("<siteMap>");

sp.Append("<siteMapNode url='" + defaultURL + "' title='" + defaultTitle + "'>");
string sturl = "";

string statictitle = "";
sturl = "About-Us.aspx";

statictitle = "About Us";

sp.Append("<siteMapNode url='" + sturl + "' title='" + statictitle + "'/>");

sturl = "ContactUs.aspx";

statictitle = "Contact Us";

sp.Append("<siteMapNode url='" + sturl + "' title='" + statictitle + "'/>");

sp.Append("</siteMapNode>");

//Fixed url complete ....................

sp.Append("</siteMapNode>");

sp.Append("</siteMap>");



xmldoc.LoadXml(sp.ToString());
 


xmldoc.Save(ConfigurationManager.AppSettings["SiteMap"] + path);

===========
in web.config
=======
<siteMap defaultProvider="XmlSiteMapProvider" enabled="true">

<providers>

<add name="XmlSiteMapProvider" description="SiteMap provider which reads in .sitemap XML files." type="System.Web.XmlSiteMapProvider, System.Web, Version=2.0.3600.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" siteMapFile="~/admin/web.sitemap" securityTrimmingEnabled="true"/>

   

</providers>

</sitemap>

==================

in asp.net design
=========
<asp:TreeView ID="TreeView1" LeafNodeStyle-ImageUrl="~/images/dot.jpg"

runat="server" ExpandDepth="1" DataSourceID="SiteMapDS"

>

<NodeStyle VerticalPadding="2" Font-Names="Verdana" Font-Size="8pt" NodeSpacing="1" HorizontalPadding="5" ForeColor="Black" />

<HoverNodeStyle BackColor="#CCCCCC" BorderColor="#888888" BorderStyle="Solid" BorderWidth="1px" Font-Underline="true" />

<SelectedNodeStyle BackColor="White" VerticalPadding="1" BorderColor="#888888" BorderStyle="Solid" BorderWidth="1px" HorizontalPadding="3" />




 
</asp:TreeView>

<asp:SiteMapDataSource ID="SiteMapDS" runat="server" SiteMapProvider="XmlSiteMapProvider"/>

====================
for bread crumb
=========================


ascx file



===
Default provider automatic fetch from web.config
===
<%@ Control Language="C#" AutoEventWireup="true" EnableViewState="false" CodeFile="BreadCrumb.ascx.cs" Inherits="UserControls_BreadCrumb" %>



 
 
<asp:SiteMapPath ID="SiteMapPath1" runat="server" SkipLinkText=" " PathSeparator=">" PathSeparatorStyle-CssClass="PathSeparator" >

<NodeTemplate>

<a href='<%# Eval("url") %>'>

            <%# Eval("title") %>

</a>

</NodeTemplate>

<CurrentNodeTemplate>

<span class="blue-text"> <%# Eval("title") %></span>

</CurrentNodeTemplate>

</asp:SiteMapPath>

==================
for calling in master page on top
<%@ Register Src="BreadCrumb.ascx" TagName="BreadCrumb" TagPrefix="uc3" %>


====
put in proper place
======
<uc3:BreadCrumb ID="BreadCrumb" runat="server" />