How many types of cookies are available in asp?
There are two type of cookies in asp.net .
——————————————————————–
Persistent cookies are stored on your computer hard disk. They stay on your hard disk and can be accessed by web servers until they are deleted or have expired. Persistent cookies are not affected by your browser setting that deletes temporary files when you close your browser.
Non-persistent cookies are saved only while your web browser is running. They can be used by a web server only until you close your browser. They are not saved on your disk. Microsoft Internet Explorer 5.5 can be configured to accept non-persistent cookies but reject persistent cookies.
Clear Cache in asp.net
It clear cache in memory
write this in aspx.vb or aspx.c# code file
——————————————————
write this at load event of page
Response.Cache.SetCacheability(HttpCacheability.NoCache)
Get the computer Name and its IP address
The following example demonstrates the use of System.NET.DNS namespace
Imports system
Imports System.Net.DNS // namespace to use class
Public Class GetIP
Shared Function GetIPAddress() As String
Dim oAddr As System.Net.IPAddress
Dim sAddr As String
With system.Net.DNS.GetHostByName(system.Net.DNS.GetHostName())
oAddr = New System.Net.IPAddress(.AddressList(0).Address)
sAddr = oAddr.ToString
End With
GetIPAddress = sAddr
End Function
Shared Sub main()
Dim shostname As String
shostname = system.Net.DNS.GetHostName
console.writeline(“Your Machine Name = ” & shostname)
‘Call Get IPAddress
console.writeline(“Your IP = ” & GetIPAddress)
End Sub
AJAX
AJAX stands for Asynchronous JavaScript and XML. AJAX is not a new technology; it is a new way of combining existing technologies. AJAX is create an asynchronous request to the web server using client-side JavaScript and an XmlHttpRequest object, and map a function to be executed when the response is received. An asynchronous request means that the browser does not need to wait for the response after sending the request to the server. we get this by sending a request to the web server for a small amount of information, as many times as we want, without sending the complete information on the form. In AJAX, the request is for data, not for a GUI element, so an AJAX request can be handled by an ASP.NET page without any HTML content, a custom HTTP module, or a web service. The core component in AJAX is the XMLHTTPRequest object.
XMLHTTPRequest
The XMLHTTPRequest object is used to send a request to, and receive a response from, the web server. Using this object, the web page can make a request to the web server asynchronously, and receive a response asynchronously
Advantages of AJAX:
1-It increases the richness of web page userinterface.
2- Avoid extra load on server
Using button field to get datakey
Scenario:
Consider we have a data grid view which show a list of books from database and you want a link button which will edit the same grid view entry but in a separate page and on separate form with the help of the primary key which you may want to send to another page using query string or else.
So the task is to get the primary key of the row on which the link button is pressed.
Solutions:
it can slove by three way
1-by using command argument
2-By using hidden field
3-by using datakeys
First of all doing it convert button field into template
Approach (1)
1- By using Command Argument.
<asp:TemplateField>
<ItemTemplate>
<asp:LinkButton ID=”Edit” CommandName=”edit” CommandArgument=’<%#Eval(”bookid”) %>‘ runat=”server”>Edit</asp:LinkButton>
</ItemTemplate>
</asp:TemplateField>
Then we write simple code on onRowCommand Event
Protected Sub GridView1_RowCommand(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewCommandEventArgs) Handles GridView1.RowCommand
If e.CommandName.ToLower() = “edit” Then
Dim Key As String = e.CommandArgument ’Getting id Value
Response.Redirect(makeeditForm.aspx?id=” + Key) ‘redirecting
End If
End Sub
———————————————————————————–
Approach (2)
2-By using hidden field
<asp:TemplateField>
<ItemTemplate>
<asp:HiddenField ID=”hidden1” runat=”server” Value=’<%#Eval(”bookid”) %>‘ />
<asp:LinkButton ID=”Edit” CommandName=”edit” runat=”server”>Edit</asp:LinkButton>
</ItemTemplate>
</asp:TemplateField>
Then we write simple code on onRowCommand Event
Protected Sub GridView1_RowCommand(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewCommandEventArgs) Handles GridView1.RowCommand
If e.CommandName.ToLower() = “edit” Then
Dim link As LinkButton = CType(e.CommandSource, LinkButton) ‘getting clicked button
Dim Key As String = CType(link.Parent.FindControl(”hidden1”), HiddenField).Value ‘getting id Value
Response.Redirect(makeeditForm.aspx?id=” + Key) ‘redirecting
End If
End Sub
—————————————————————————————
Approach(3)
3-by using datakeys
<asp:TemplateField>
<ItemTemplate>
<asp:LinkButton ID=”Edit” CommandName=”edit” runat=”server”>Edit</asp:LinkButton>
</ItemTemplate>
</asp:TemplateField>
Then we write simple code on onRowCommand Event
Protected Sub GridView1_RowCommand(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewCommandEventArgs) Handles GridView1.RowCommand
If e.CommandName.ToLower() = “edit” Then
Dim link As LinkButton = CType(e.CommandSource, LinkButton) ‘getting clicked button
Dim Row As GridViewRow = link.NamingContainer ‘Getting current row to get index
Dim Key As String = GridView1.DataKeys(Row.RowIndex)(0).ToString()
Response.Redirect(makeeditForm.aspx?id=” + Key) ‘redirecting
End If
End Sub
-
Archives
- January 2015 (1)
- December 2014 (1)
- February 2014 (1)
- August 2011 (1)
- July 2011 (2)
- March 2011 (1)
- August 2009 (3)
- July 2009 (3)
- June 2009 (1)
- May 2009 (9)
- April 2009 (5)
-
Categories
-
RSS
Entries RSS
Comments RSS