Monday, 3 February 2014

How to use two update panel in asp.net



During Development we Select Country from a dropdown list controls and waiting for the State/City of that country on our form we will see full postback of our page and we will lost all the controls values whatever we entered previously this happend because of postback. If we want to avoid this full postback of page and round trip to server we need to write much code instead of writing much code we can use ajax updatepanel control. for this first you have to use a Script Manager on your page.

Ajax updatepanel will help us to avoid full postback of the page like avoid refresh of the whole page content with postback and stop flickering of the page which is associated with a postback and allows only partial postbacks. By using Ajax updatepanel we can refresh only required part of page instead of refreshing whole page.

ContentTemplate is used to hold the content of the page like controls

Triggers we used in a situation like when and where we want to refresh our page.

A sample Update Panel Example.

 <tr>
                <td>
                    <asp:UpdatePanel runat="server" ID="up1" UpdateMode="Conditional">
                    <ContentTemplate>
                    <asp:DropDownList ID="DropDownList1" runat="server" onselectedindexchanged="DropDownList1_SelectedIndexChanged"
                        AutoPostBack="true">
                    </asp:DropDownList>
                    </ContentTemplate>
                   
                    </asp:UpdatePanel>
                </td>
                <td>
                    &nbsp;</td>
            </tr>
            <tr>
                <td>
                    <asp:UpdatePanel runat="server" ID="up2" UpdateMode="Conditional">
                    <ContentTemplate>
                    <asp:DropDownList ID="DropDownList2" runat="server">
                    </asp:DropDownList>
                    </ContentTemplate>
                    <Triggers>
                        <asp:AsyncPostBackTrigger ControlID="DropDownList1" EventName="SelectedIndexChanged" />
                    </Triggers>
                    </asp:UpdatePanel>
                </td>
                <td>
                    &nbsp;</td>
            </tr>


In .CS page

SqlConnection con = new SqlConnection("Data Source=TestDB;Initial Catalog=Test;User ID=SQLServer;Password=*******");
    SqlDataAdapter da;
    DataTable dt;
    protected void Page_Load(object sender, EventArgs e)
    {
        da = new SqlDataAdapter("select * from country", con);
        dt = new DataTable();
        da.Fill(dt);
        DropDownList1.DataSource = dt;
        DropDownList1.DataTextField = "Country_Name";
        DropDownList1.DataValueField = "country_id";
        if (!IsPostBack)
        {
            DropDownList1.DataBind();
        }

    }
    protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e)
    {
        da = new SqlDataAdapter("select * from State where Country_Id='"+DropDownList1.SelectedValue+"'", con);
        dt = new DataTable();
        da.Fill(dt);
        DropDownList2.DataSource = dt;
        DropDownList2.DataTextField = "State_Name";
        DropDownList2.DataValueField = "State_Id";
         DropDownList2.DataBind();
         up2.Update();
    }

Wednesday, 8 January 2014

How to hide a .aspx extension in browser using asp.net c#?

Hello Friends,
Today i'll tell you, how to hide extension of ur .ASPX page in Dot Net. i am explaing it by creating a small project.

Step 1 : Create a new website and add one Global.asax file.

Step 2 : In Application_Start method you need to Write

           RouteTable.Routes.MapPageRoute("StoreRoute", "HideExtension/{Name}", "~/{Name}.aspx");




Step 3 : Take one master page or Default page, take Linkbutton to create a Menu bar like this. i m taking three page Name is Index.aspx, Company.aspx and Client.aspx.



Step 4 : In source code of Hyperlink button, you need to initialize navigateurl  with your RouteUrl

<asp:HyperLink runat="server" id="h1" Text="index" NavigateUrl="<%$RouteUrl:Name=Index %>">Home</asp:HyperLink>
  

Now after running your site, you can see after clicking on every button(Hyperlink Button) you got the page with no extension.

Saturday, 26 October 2013

How to Integrate XML in ADO.NET applications

Extensible Markup Language (XML) is a markup laguage that defines a set of rules for encoding documents in a format that is both human readable and machine readable.

You can Make your own XML file and integrate with your Dataset or Datatable as per your Requirement. Here I am writing some steps, after follow this step you can integrate your XML file.

1. first create a test.xml file like this given code

<?xml version="1.0" encoding="utf-8" ?>
<HrSolution>
  <HrEmployee>
    <EmployeeID>123</EmployeeID>
    <EmployeeName>Nirja</EmployeeName>
    <EmployeeSalary>19000</EmployeeSalary>
    <EmployeeAddress>Address</EmployeeAddress>
  </HrEmployee>
  <HrEmployee>
    <EmployeeID>124</EmployeeID>
    <EmployeeName>Priya</EmployeeName>
    <EmployeeSalary>20000</EmployeeSalary>
    <EmployeeAddress>Address</EmployeeAddress>
  </HrEmployee>
  <HrEmployee>
    <EmployeeID>125</EmployeeID>
    <EmployeeName>Deepika</EmployeeName>
    <EmployeeSalary>12000</EmployeeSalary>
    <EmployeeAddress>Address</EmployeeAddress>
  </HrEmployee>
  <HrEmployee>
    <EmployeeID>126</EmployeeID>
    <EmployeeName>Gayatri</EmployeeName>
    <EmployeeSalary>22000</EmployeeSalary>
    <EmployeeAddress>Address</EmployeeAddress>
  </HrEmployee>
  <HrEmployee>
    <EmployeeID>127</EmployeeID>
    <EmployeeName>Ramesh</EmployeeName>
    <EmployeeSalary>18000</EmployeeSalary>
    <EmployeeAddress>Address</EmployeeAddress>
  </HrEmployee>
</HrSolution>


2. Now add your gridview and on Button click write this code

        DataSet ds = new DataSet();

         //XML read by Dataset
        ds.ReadXml(Request.MapPath("test.xml"));

        //Show xml contents to the GridView
        GridView1.DataSource = ds.Tables[0];
        GridView1.DataBind();


Monday, 7 October 2013

How to do Asp.Net textbox validation in javascript


In this Section we learn how to do client side validation through javascript
 First we add Textbox  in our Validation.aspx page like this



OnClientClick="return validate();" is used to call the JavaScript function on click of the Submit button

Now in the validate() function, we will get the value of textboxes and check textboxes are blank or not like below:


Now for email value we will create a parameter that finds if the email format is valid or not as well as Given Password is same or not.

When user enters wrong information or may the user leaves a textbox blank, then the client side validation will be work. This will reduce server traffic and page reload problem

Tuesday, 1 October 2013

How to do ccavenue payment gateway integration in asp.net

When you buy Payment gateway from CCAvenue, they send you Integration_kit which have some library under Libs folder, add those dll to your Gac  and also you will get three .aspx pages , Data.aspx, SubmitData.aspx and ResponseHandler.aspx. you dont need to change any value of these page.

Payment Gateway always integrate with your checkout button. In checkout button you have to pass four thing. Order Id, Merchant Id, RedirectUrl and Amount. Order id must be unique.




Now your all information send to your Data.aspx page, through querystring get it into your textbox like this


Goto your SubmitData.aspx page and write your working key which you get after login into your CCAvenue account.





Now by this step you can integrate your Avenue gateway in your Asp.net page, Enjoy.....


Monday, 30 September 2013

How to: Install an Assembly into the Global Assembly Cache

To install a strong-named assembly into the global assembly cache using the Global Assembly Cache tool (Gacutil.exe)

 1. Goto your Visual Studio Command Prompt, right click and Run as Administrator

 2. Now You can see your Command prompt Window will appear., go to your source path of Dll, like bin directory of your Project

3. Now type Gacutil /i <Dll Name>.dll



The following steps installs an assembly into the global assembly cache.


Saturday, 28 September 2013

How to configure mail Settings in asp.net through SMTP

public void sendmail()
    {
        MailMessage msg = new MailMessage();
//From Address
        msg.From = new MailAddress(“abc@abc.com”);
//To Address
        msg.To.Add(“xyz@xyz.com”);
// Your  message Subject
        msg.Subject = “Your Message Subject”;
//Your message Body
        msg.Body = “Your Message Body”;

        msg.IsBodyHtml = true;
        SmtpClient smtpClient = new SmtpClient();
//Please write your DNS name instead of abc.com

        smtpClient.Host = “smtp.abc.com”;
//either you select port 25 or 587 as per your requirement
       smtpClient.Port = 25;
        smtpClient.EnableSsl = false;
        smtpClient.DeliveryMethod = System.Net.Mail.SmtpDeliveryMethod.Network;

        smtpClient.Credentials = new NetworkCredential(msg.From.ToString(), “your password”);
// For Maximum timeout
        smtpClient.Timeout = 20000;
        smtpClient.Send(msg);
    }