Search This Blog

Saturday, October 27, 2012

How to redirect users from domain.com to http:www.domain.com

Here is the answer.


Use .htaccess file in the root directory.

open notepad.exe and create file name .htaccesss


in that file write code


RewriteEngine On
RewriteCond %{HTTP_HOST} ^mydomain.com$
RewriteRule ^$ http://www.mydomain.com/index.html [L,R=301]



NOTE : FILE MUST BE PUT ON THE ROOT DIRECTORY AND MUST HAVE NAME AS .HTACCESS

Friday, October 19, 2012

Introduction to JQuery

Definition of Jquery 

Jquery : It is a scripting language based on javascript, which contain rich set of built in function so it is very easy to use the jquery in your website. 
                We can create animation on the webpage with the help of jquery. we can also add some interactive programming effects which user wants to see on the webpage using jquery. Now a days jquery is one of the popular scripting language. 

Here some examples are given to show the use of jquery on the website.

Hide and show division or whatever in the division tag like if you want to hide the image then put it inside the division tag.
Division id is #divSample

1000millisecond will taken to show the output on the screen. YOu can change the  Time according to your need into the webpage or web application.

.aspx File

<script type="text/javascript">
  function showbtn()
  {
      $('#divSample').show(1000); 
  }

  function hidebtn()
  {
      $('#divSample').hide(1000); 
  }
</script> 

<body>
<div id="divSample" >
<img src="Image1.jpg" height="200px" width="200px" title="jquery" text="ShowImage" />
</div>
<asp:Button id="b1" runat="server" onclientclick="showbtn();">
</asp:Button>
<asp:Button id="b2" runat="server" onclientclick="hidebtn();" text="HideImage">
</asp:Button>
</body>


The output is wonderful.
so try it your self with littlebit work on this code and you can create innovation in your technology.

I had brief out some other function which can be used as above.

 $('#divSample2').slideUp(2000); 
            
 $('#divSample2').slideDown(2000);


 $('#divSample3').fadeOut(2000); 
            
 $('#divSample3').fadeIn(1100);


Animation with the use of JQuery.

YOu can also create animation with the help of animate function.


$("#divSample").animate({height:500, width:750 , opacity: .7}, 3000, function() {alert("DivSample is having 500px height and 750px width"); });


This will create your division of image large upto 500px height and 750px width.
and after completion of it with opacity of 70%.
 It displays the message that DivSample is having 500px height and 750px width
in the Alert box.
                

Thursday, October 18, 2012

What is JQuery ??? How to use it with Asp.net???

I think you all have to know little bit about the new invention in Technology.or How to use that with the Asp.net.

"JQuery is a cross browser JavaScript library that helps to traverse through HTML elements, event handling, effects(animation) and Ajax interactions."

It is very easy to learn and implement features in out application with the help of JQuery.

Here is Sample Example is given related to it.

Add Script tag into .aspx File for using JQuery on to the Webpage.


<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.2.6/jquery.min.js">  
</script>

OR aspx.cs File 

protected override void Render(HtmlTextWriter writer)
{
this.Page.ClientScript.RegisterClientScriptInclude("jQuery", "http://ajax.googleapis.com/ajax/libs/jquery/1.2.6/jquery.min.js");
base.Render(writer);
}

e.g. Display "Hi, Hitesh!" message on the webpage.

.aspx file : 
        
        <html xmlns="http://www.w3.org/1999/xhtml">
        <head runat="server">
            
            <script type="text/javascript">
            function hi()
            {
                $("#divSample").append("Hi, Hitesh!");
            }
            </script>

        </head>
        <body>
            <form id="form1" runat="server">
                <div id="divSample">
                </div>
            </form>
        </body>
        </html>
        
And Aspx.cs File
            
protected override void Render(HtmlTextWriter writer)
 {
 this.Page.ClientScript.RegisterClientScriptInclude("jQuery", "http://ajax.google  apis.com/ajax/libs/jquery/1.2.6/jquery.min.js");
 this.Page.ClientScript.RegisterStartupScript(this.Page.GetType(), "startup", "<s  cript type=\"text/javascript\">hi();</script>");
 base.Render(writer);
}




Tuesday, October 9, 2012

New features of asp.net 4.5 vs 4.0 framework


1. Asynchronously Reading and Writing HTTP Requests and Responses while in asp.net 4.0 it happens synchronously.
ASP.NET 4 introduced the ability to read an HTTP request entity as a stream using the HttpRequest.GetBufferlessInputStream method. This method provided streaming access to the request entity. However, it executed synchronously, which tied up a thread for the duration of a
request.ASP.NET 4.5 supports the ability to read streams asynchronously on an HTTP request entity, and the ability to flush asynchronously. ASP.NET 4.5 also gives you the ability to double-buffer an HTTP request entity, which provides easier integration with downstream HTTP handlers such as .aspx page handlers and ASP.NET MVC controllers.

2.Support for await and Task-Based Asynchronous Modules and Handlers
The .NET Framework 4 introduced an asynchronous programming concept referred to as a task. Tasks are represented by the Task type and related types in the System.Threading.Tasks namespace. The .NET Framework 4.5 builds on this with compiler enhancements that make working with Task objects simple. In the .NET Framework 4.5, the compilers support two new keywords: await and async.

3.Support for WebSockets Protocol
WebSockets protocol is a standards-based network protocol that defines how to establish secure, real-time bidirectional communications between a client and a server over HTTP. Microsoft has worked with both the IETF and W3C standards bodies to help define the protocol. The WebSockets
protocol is supported by any client (not just browsers), with Microsoft investing substantial resources supporting WebSockets protocol on both client and mobile operating systems.WebSockets protocol makes it much easier to create long-running data transfers between a client and a server. For example, writing a chat application is much easier because you can establish a true long-running connection between a client and a server.

4.Bundling and Minification
Bundling lets you combine individual JavaScript and CSS files into a bundle that can be treated like a single file. Minification condenses JavaScript and CSS files by removing whitespace and other characters that are not required. These features work with Web Forms, ASP.NET MVC, and Web Pages.

5.Performance Improvements for Web Hosting
The .NET Framework 4.5 and Windows 8 introduce features that can help you achieve a significant
performance boost for web-server workloads. This includes a reduction (up to 35%) in both startup time and in the memory footprint of web hosting sites that use ASP.NET.

6.Unobtrusive Validation
You can now configure the built-in validator controls to use unobtrusive JavaScript for client-side validation logic. This significantly reduces the amount of JavaScript rendered inline in the page markup and reduces the overall page size.

7.Provides HTML editor, Javascript Editor and CSS editor with smart and intelligent features.


Wednesday, March 21, 2012

Confirm on Delete in Gridview using Javascript ?

When You Press on Delete Button in the Gridview At that time confimation is there For Delete Particular Row from the Database .


Press Delete

At that time confirmation block will be generated.

On aspx Page Write Javascript as shown Below.

<head runat="server">
    <title></title>
    <script type="text/javascript">
        function onconfirm() {
        return confirm('Are You Sure ???')
        }
    </script>
</head>

And In the Body Part code inside the gridview :

<asp:GridView ID="GridView1" runat="server" BackColor="White" BorderColor="#999999" BorderStyle="Solid" BorderWidth="1px" CellPadding="3" ForeColor="Black" GridLines="Vertical"
Width="754px" AutoGenerateColumns="False" DataKeyNames="country_id" onrowcancelingedit="GridView1_RowCancelingEdit" onrowcommand="GridView1_RowCommand" onrowdeleting="GridView1_RowDeleting"  onrowediting="GridView1_RowEditing" onrowupdating="GridView1_RowUpdating"  onsorting="GridView1_Sorting">
   <Columns>
   </asp:TemplateField>                                                                                                       
<ItemTemplate>
   <asp:LinkButton ID="LinkButton1" runat="server" OnClientClick="return onconfirm();" CommandArgument='<%# Bind("country_id") %>' CommandName="Delete">Delete</asp:LinkButton>
 </ItemTemplate>
   </asp:TemplateField>                                                               
  </Columns>                                                          
 </asp:GridView>

IN aspx.cs File

DAL_Country d1 = new DAL_Country();
BAL_Country b1 = new BAL_Country();
 public void ShowData()
    {
        DataSet ds = new DataSet();
        ds = b1.SelectData();
        GridView1.DataSource = ds;
        GridView1.DataBind();
    }
protected void GridView1_RowDeleting(object sender, GridViewDeleteEventArgs e)
    {
        int id = int.Parse(GridView1.DataKeys[e.RowIndex].Value.ToString());
        b1.DeleteData(id);
        ShowData();
    }
public DataSet SelectData()
    {
        SqlDataAdapter da = new SqlDataAdapter("select * from tbl_country",con);
        DataSet ds = new DataSet();
        da.Fill(ds);
        return ds;
    }
BAL_Country.cs File
    public void DeleteData(int id)
    {
        con.Open();
        SqlCommand cmd = new SqlCommand("delete from tbl_country where country_id='"+id+"'",con);
        cmd.ExecuteNonQuery();
        con.Close();
    }

Thursday, March 15, 2012

Upload Product Information



Aspx File Source Code
<table class="style1">
                                                <tr>
                                                    <td class="style2">
                                                        Product Category
                                                    </td>
                                                    <td class="style3">
                                                        <strong>:-</strong>
                                                    </td>
                                                    <td>
                                                        <asp:DropDownList ID="Ddl_Category" runat="server" AutoPostBack="True" ForeColor="#009933"
                                                            OnSelectedIndexChanged="Ddl_Category_SelectedIndexChanged">
                                                        </asp:DropDownList>
                                                    </td>
                                                </tr>
                                                <tr>
                                                    <td class="style2">
                                                        Product SubCategory
                                                    </td>
                                                    <td class="style3">
                                                        <strong>:-</strong>
                                                    </td>
                                                    <td>
                                                        <asp:DropDownList ID="Ddl_SubCategory" runat="server" AutoPostBack="True" ForeColor="#009933">
                                                        </asp:DropDownList>
                                                    </td>
                                                </tr>
                                                <tr>
                                                    <td class="style2">
                                                        Product Name
                                                    </td>
                                                    <td class="style3">
                                                        <strong>:-</strong>
                                                    </td>
                                                    <td>
                                                        <asp:TextBox ID="Txt_ProductName" runat="server" Font-Bold="True" ForeColor="#009933"></asp:TextBox>
                                                    </td>
                                                </tr>
                                                <tr>
                                                    <td class="style2">
                                                        Product Price
                                                    </td>
                                                    <td class="style3">
                                                        <strong>:-</strong>
                                                    </td>
                                                    <td>
                                                        <asp:TextBox ID="Txt_ProductPrice" runat="server" Font-Bold="True" ForeColor="#009933"></asp:TextBox>
                                                    </td>
                                                </tr>
                                                <tr>
                                                    <td class="style2">
                                                        Product Image
                                                    </td>
                                                    <td class="style3">
                                                        &nbsp;
                                                    </td>
                                                    <td>
                                                        <asp:FileUpload ID="FileUpload1" runat="server" />
                                                    </td>
                                                </tr>
                                                <tr>
                                                    <td class="style2">
                                                        Product Color
                                                    </td>
                                                    <td class="style3">
                                                        <strong>:-</strong>
                                                    </td>
                                                    <td>
                                                        <asp:DropDownList ID="Ddl_Color" runat="server" AutoPostBack="True" ForeColor="#009900">
                                                            <asp:ListItem Value="0">--select color--</asp:ListItem>
                                                            <asp:ListItem Value="White">White</asp:ListItem>
                                                            <asp:ListItem>Red</asp:ListItem>
                                                            <asp:ListItem>Green</asp:ListItem>
                                                            <asp:ListItem>Yellow</asp:ListItem>
                                                            <asp:ListItem>Black</asp:ListItem>
                                                            <asp:ListItem>Blue</asp:ListItem>
                                                            <asp:ListItem>Gray</asp:ListItem>
                                                            <asp:ListItem>Orange</asp:ListItem>
                                                            <asp:ListItem>Pink</asp:ListItem>
                                                        </asp:DropDownList>
                                                    </td>
                                                </tr>
                                                <tr>
                                                    <td class="style2">
                                                        Product Features
                                                    </td>
                                                    <td class="style3">
                                                        <strong>:-</strong>
                                                    </td>
                                                    <td>
                                                        <asp:TextBox ID="Txt_ProductFeatures" runat="server" Font-Bold="True" ForeColor="#009933"
                                                            TextMode="MultiLine" Height="46px" Width="250px"></asp:TextBox>
                                                    </td>
                                                </tr>
                                                <tr>
                                                    <td class="style2">
                                                        Product Specification
                                                    </td>
                                                    <td class="style3">
                                                        <strong>:-</strong>
                                                    </td>
                                                    <td>
                                                        <asp:TextBox ID="Txt_ProductSpecification" runat="server" Font-Bold="True" ForeColor="#009933"
                                                            TextMode="MultiLine" Height="45px" Width="250px"></asp:TextBox>
                                                    </td>
                                                </tr>
                                                <tr>
                                                    <td class="style2">
                                                        Product Description
                                                    </td>
                                                    <td class="style3">
                                                        <strong>:-</strong>
                                                    </td>
                                                    <td>
                                                        <asp:TextBox ID="Txt_ProductDescription" runat="server" Font-Bold="True" ForeColor="#009933"
                                                            TextMode="MultiLine" Height="46px" Width="250px"></asp:TextBox>
                                                    </td>
                                                </tr>
                                                <tr>
                                                    <td class="style5">
                                                        Product Warranty
                                                    </td>
                                                    <td class="style6">
                                                        <strong>:-</strong>
                                                    </td>
                                                    <td class="style7">
                                                        <asp:TextBox ID="Txt_ProductWarranty" runat="server" Font-Bold="True" ForeColor="#009933"></asp:TextBox>
                                                    </td>
                                                </tr>
                                                <tr>
                                                    <td class="style2">
                                                        Available Quantity
                                                    </td>
                                                    <td class="style3">
                                                        <strong>:-</strong>
                                                    </td>
                                                    <td>
                                                        <asp:TextBox ID="Txt_ProductQuantity" runat="server" Font-Bold="True" ForeColor="#009933"></asp:TextBox>
                                                    </td>
                                                </tr>
                                                <tr>
                                                    <td class="style2">
                                                        &nbsp;
                                                    </td>
                                                    <td class="style3">
                                                        &nbsp;
                                                    </td>
                                                    <td>
                                                        <asp:Button ID="Btn_Upload" runat="server" Text="Upload" OnClick="Btn_Upload_Click" />
                                                    </td>
                                                </tr>
                                            </table>


In aspx .cs File the Code To upload all the Information of Product

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.Data.SqlClient;

public partial class ProductUpload : System.Web.UI.Page
{
    SqlConnection con = new SqlConnection("Data Source=TOPS21;Initial Catalog=MyExample;Integrated Security=True;Pooling=False");
    static string path = "";
    static string filename = "";
    protected void Page_Load(object sender, EventArgs e)
    {
        con.Open();
        if (!IsPostBack)
        {
            Fill_DdlCategory();
        }
    }
    public void Fill_DdlCategory()
    {
        SqlDataAdapter da = new SqlDataAdapter("select * from tbl_category",con);
        DataSet ds = new DataSet();
        da.Fill(ds);
        Ddl_Category.DataSource = ds;
        Ddl_Category.DataValueField = "category_id";
        Ddl_Category.DataTextField = "category_name";
        Ddl_Category.DataBind();
        Ddl_Category.Items.Insert(0,new ListItem("--select category--","0"));
        Ddl_SubCategory.Items.Insert(0, new ListItem("--select subcategory--", "0"));
    }
    protected void Ddl_Category_SelectedIndexChanged(object sender, EventArgs e)
    {
        SqlDataAdapter da = new SqlDataAdapter("select * from tbl_subcategory where category_id='"+Ddl_Category.SelectedValue+"'", con);
        DataSet ds = new DataSet();
        da.Fill(ds);
        Ddl_SubCategory.DataSource = ds;
        Ddl_SubCategory.DataValueField = "subcategory_id";
        Ddl_SubCategory.DataTextField = "subcategory_name";
        Ddl_SubCategory.DataBind();
        Ddl_SubCategory.Items.Insert(0, new ListItem("--select subcategory--", "0"));   
    }
    protected void Btn_Upload_Click(object sender, EventArgs e)
    {
        if (FileUpload1.HasFile)
        {
            filename = FileUpload1.FileName;
            path = "~//images//" + filename;
            FileUpload1.SaveAs(Server.MapPath(path));
            SqlCommand cmd = new SqlCommand("insert into tbl_product values('" + Ddl_Category.SelectedValue + "','" + Ddl_SubCategory.SelectedValue + "','" + Txt_ProductName.Text + "','" + Txt_ProductPrice.Text + "','" + path + "','" + Ddl_Color.SelectedValue + "','" + Txt_ProductFeatures.Text + "','" + Txt_ProductSpecification.Text + "','" + Txt_ProductDescription.Text + "','" + Txt_ProductWarranty.Text + "','" + Txt_ProductQuantity.Text + "')", con);
            cmd.ExecuteNonQuery();
            con.Close();
            lblmsg.Text = "Product Uploaded...";
        }
        else
        {
            lblmsg.ForeColor = System.Drawing.Color.Red;
            lblmsg.Font.Bold.Equals(true);
            lblmsg.Text = "Please select the Product Image First.";
        }
    }
}

Output is

For that Make table in the database