vijay

welcome Netizen

Share Your Knowledge.It is a way to achieve immortality

Thursday, May 31, 2012

How to use fileupload control inside update panel in gridview or listview?


Here i discuss the issues i come across recently, if you are using fileupload control without update panel then its working
Fine, but if you use update panel then fileupload control has loss the selected file when asynchronous postback.
Solution for this problem has we have to trigger the control when asynchronous postback occurs.
These are the following solution to overcome the issues.
File upload control without using gridview
<table width="50%" cellpadding="2" cellspacing="0">
<tr>
<td>
<asp:UpdatePanel ID="UpdatePanel1" runat="server" UpdateMode="conditional">
<ContentTemplate>
<asp:FileUpload ID="FileUpload1" runat="server" />
<asp:Button ID="btnUpload" runat="server" Text="Upload" OnClick="Upload_Click" /><br />
</ContentTemplate>
<Triggers>
<asp:PostBackTrigger ControlID="btnUpload" />
</Triggers>

</
asp:UpdatePanel>
</td>
</tr>
</table>


Using gridview
When without using gridview we directly give the button control id to the trigger.
Suppose if you are using gridview, simple solution is then give the grid view control id as postbacktrigger, then it will find the button control..
<Triggers>
                        <asp:PostBackTrigger ControlID="GridView1" />
                </Triggers>

Or
You need to add trigger dynamically in gridview.After binding the data you have to add below code..


GridView1.DataSource = lst;
           GridView1.DataBind();         
 PostBackTrigger posttrg = new PostBackTrigger();
           posttrg.ControlID = this.GridView1.FooterRow.FindControl("btnUpload").UniqueID;
           this.UpdatePanel1.Triggers.Add(posttrg);

Or
Write the code in prerender event
protected override void OnPreRender(EventArgs e)
         {
             PostBackTrigger posttrg = new PostBackTrigger();
             posttrg.ControlID = this.GridView1.FooterRow.FindControl("btnUpload").UniqueID;
             this.UpdatePanel1.Triggers.Add(posttrg);
             base.OnPreRender(e);
         }

Using Listview Control:
  posttrg.ControlID = ListView1.InsertItem.FindControl("btnUpdate").UniqueID
        posttrg.ControlID = ListView1.EditItem.FindControl("btnUpdate").UniqueID
        Me.UpdatePanel1.Triggers.Add(posttrg)

I hope it will be useful for someone ……Happy coding and keep reading

Wednesday, May 30, 2012

What Is SSL (Secure Socket Layer) and How its work?


Secure Socket Layer (SSL) certificates are widely used to help secure and authenticate communications both on  the Internet and within organizational intranets.

History:

SSL is a protocol developed by Netscape in 1995, which quickly became the preferred method for securing data transmissions across the Internet.
SSL is built into every major web server and web browser and makes use of public-private key encryption techniques originally developed by RSA. To make an SSL connection, a web server must have a digital certificate installed; this certificate utilizes the public and private keys used for encryption, and the certificate uniquely and positively identifies the server. You can think of digital certificates as a kind of electronic identification card, not unlike a driver’s license or national identity card, which authenticates the server to the client before establishing an encrypted communications channel. Typically, digital certificates are issued by an independent, trusted third-party to ensure their validity and broad acceptance. The issuer of a certificate is also known as a Certification Authority (CA).
Features of SSL:
People tend to associate SSL with encryption, but in fact, an SSL certificate provides four distinct features,
·         Encryption
·         Integrity
·         Authentication
·         Non-Repudation

ENCRYPTION
Encryption utilizes mathematical algorithms to transform data so that it can only be read by the intended parties. In the case of SSL, the private and public keys provided as part of the server’s digital certificate play an important role in securing data sent to and from the web browser.
INTEGRITY
By encrypting data so that only the intended parties can read it, SSL certificates also ensure the integrity of that data. In other words, if nobody else can successfully read the data, the data cannot be modified in transit. Modifying the encrypted data would render it useless, and the intended parties would then know that someone had tried to tamper with the data.understanding SSL certificates2
AUTHENTICATION
One of the primary roles of the CA in issuing a digital certificate is to validate the identity of the organization, or person, requesting the certificate. SSL certificates are tied to an Internet domain name, and by verifying ownership of that name, a CA ensures that users know with whom they are dealing at a basic level. For example, when you connect to an SSL-enabled web site, such as Amazon.com, the certificate identifies its owner as Amazon, Inc., and you can be sure that you are dealing with Amazon.

NON-REPUDIATION
Encryption, integrity, and authentication combine to establish non-repudiation, which means that neither party in a secured transaction can legitimately state that their communications came from someone other than themselves. This feature removes the option for one party to repudiate, or “take back,” information that they have communicated online
Applications of SSL
SSL can be used in many ways and for different purposes:
• Browser-to-server communications—Most commonly, SSL is used to secure communications between a web server and a web browser, often when sensitive information is being transmitted. This nformation may relate to an online purchase, a patient’s medical data, or banking details. SSL helps ensure that the user of the web browser knows to whom their information is being sent and that only the intended recipient can access the information.

• Server-to-server communications—SSL can also be used to secure communications between two servers, such as two businesses that transact with one another. In this scenario, both servers usually have a certificate, mutually authenticating them to each other as well as securing the communications between them.

• Compliance with legislative and industry requirements—Many legal and industry requirements call for levels of authentication and privacy that SSL certificates provide. The Payment Card Industry Data Security Standard (PCI DSS), for example, requires the use of authentication and encryption technologies during any online payment transaction

 HOW IS AN SSL SESSION CREATED?
An SSL session begins when a web browser sends a request to a web server using the https:// protocol 
The web server responds with its digital ID, which includes its public encryption key. The web browser verifies the digital ID, which may include an online check with the CA as well as a check of the certificate itself for validity dates and other details. Once verified, the browser generates a session key, encrypts the session key using the server’s public key, and sends the package back to the server.

The server decrypts the session key by using the server’s private encryption key, which only the server
possesses. This ensures that only the browser and the server possess the session key, and they can use
that shared key to encrypt further communications between them. Servers usually discard session keys after
several minutes of inactivity


Tuesday, May 29, 2012

Refersh gridview for an every 10 second in asp.net


Introduction:

Here this article discuss about to refresh the grid view content on every 10 seconds.
This process accomplish by using JavaScript, Here we use the grid view inside the update panel so refresh occurs by asynchronously.
By using JavaScript, we call the button event for an every 10 second the data have been checking and refresh for an every 10 second.
In that button event you can write the code to bind the value in gridview.

Javascript Code:
<script type="text/javascript" language="javascript">
  Sys.WebForms.PageRequestManager.getInstance().add_pageLoaded(refreshClick);
  function refreshClick(sender, args) {
    button = $get("<%= buttonUpdate.ClientID %>");
    setTimeout(function() { button.click(); }, 0000);
  }
</script>

<asp:UpdatePanel ID="updateGrid" runat="server" UpdateMode="Conditional">
            <ContentTemplate>
                <asp:GridView ID="gridAutoUpdate" runat="server">
                </asp:GridView>
                <asp:Button ID="buttonUpdate" runat="server" Style="display: none" OnClick="buttonUpdate_Click" />
            </ContentTemplate>
        </asp:UpdatePanel>

I hope you like this ..happy coding

Bind data in gridview using List in asp.net


Introduction:
Here we discuss about to find the alternate way to bind the data in gridview or datalist or repeater control.
Usually we used the dataset or datatable to bind the data in gridview, but here new way of binding is using List type.
Here what we going to do create a new list with some data and bind the data in gridview. This process must help when using web service.
Because they mostly used class in web service, by creating list is the best way to bind in data control.

Initially we see the design view code..
<div>
        <asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="false">
            <Columns>
                <asp:BoundField HeaderText="Name" DataField="name" />
                <asp:BoundField HeaderText="Rollno" DataField="roll" />
            </Columns>
        </asp:GridView>
    </div>

C# code:
First we create a one class by using the class store the data by get set method...
public class stud
    {
        public stud(string name,string roll)
        {
           _name=name;
            _rollno =roll;
        }
        private string _name;
        private string _rollno;

        public string name
    {
       get {return _name;}
         set { _name=value ;}
    }
        public string roll{
            get{return _rollno;}
            set{_rollno =value;}
        }
      
}

protected void Page_Load(object sender, EventArgs e)
        {
            List <stud > lst=new List<stud>() ;
            lst.Add(new stud("Raj", "01"));
            lst.Add(new stud("Kumar", "02"));
            lst.Add(new stud("Rahul", "03"));
             //*******Here we bind the list type in grid view*******/
             /**************www.dotnetcode.in***********************/
           GridView1.DataSource = lst;
           GridView1.DataBind();
        }

VB code:
Public Class customer
        Public Sub New(ByVal name As String, ByVal roll As String)
            _name = name
            _roll = roll
        End Sub
        Private _name As String
        Private _roll As String

        Public Property name() As String
            Get
                Return _name
            End Get
            Set(ByVal value As String)
                _name = value
            End Set
        End Property

        Public Property roll() As String
            Get
                Return _roll
            End Get
            Set(ByVal value As String)
                _roll = value
            End Set
        End Property
    End Class
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        loadgrd()
    End Sub
Sub loadgrd()
        fselect = "select * from phone"
        rtable = obj.ExecuteData(fselect)
        Dim stud As List(Of customer) = New List(Of customer)()
        stud.Add(New customer("Ram", "45"))
        stud.Add(New customer("Kavitha", "50"))
        stud.Add(New customer("Neha", "60"))
        GridView1.DataSource = stud
        GridView1.DataBind()
    End Sub