vijay

welcome Netizen

welcome Netizen
Hi folks this site Share Basic Knowledge in .NET, DotNet, C#,DOT NET CODE, ASP.NET, VB.NET, DOT NET TRICKS,Dotnetcode,Android and Latest Technology Articles in VB,Android and ASP.NET

Thursday, August 25, 2011

Store user name in cookies using ASP.Net


Hi ..
In this article I am going to explain about usage of cookies, Normally cookies are used to store temporary data. Cookies will be remain the data up to clear cookies in browser.
Using cookies we can store the user related information, also we can retrieve the information from the cookies data. Normally cookies are used to track the user. The data is stored in browser until clear the cookies.
Ex: For checking email, when enter username below they mention you want to remember username, if you checked the box then the username is stored in the cookies…same process I follow here …
Below I have mentioned the code to store the values in cookies…….
When user enter the username….write the below code..

Response.Cookies("username").Value = txtusername.Text

Also we can set expiry date for cookies

Response.Cookies("username").Expires = Now.AddDays(1)

Then page init write the below code to store the username in textbox…..
Protected Sub Page_Init(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Init
    If Not Request.Cookies("username") Is Nothing Then
     txtusername.Text = Request.Cookies("username").Value
        End If
    End Sub
So when store we use response and when get the data use request in cookies
I hope this one helpful to all…
Post your valuable comments……….

Monday, August 22, 2011

Sys.WebForms.PageRequestManagerServerErrorException: Invalid postback or callback argument. Event validation is enabled using in configuration or <%@ Page EnableEventValidation="true" %> in a page.


hi.i got this error when i kept datalist control in update panel...In datalist control i kept one image button when i click the image button i got this type of error..

Sys.WebForms.PageRequestManagerServerErrorException: Invalid postback or callback argument.  Event validation is enabled using <pages enableEventValidation="true"/> in configuration or <%@ Page EnableEventValidation="true" %> in a page.

Then i found a way to fix this error....

To fix:

To fix the error add Enableviewstate ="false" in datalist..
<asp:DataList Width="100%" ID="DataList1" runat="server" RepeatColumns="3" RepeatDirection="Horizontal" DataKeyField ="ID" EnableViewState ="false">

By adding this code the error will be fixed.......


i hope this one be useful to all.........


Thursday, August 18, 2011

Cross Browser compatibility issue for IE


Hi..
Recently I have struggled to view my site to all browser,Each browser have get the code differently.For internet explorer to fix the problem I found an solution to fix it..
I add the below code in page header then I change the compatibility view and check all version in IE..then it will support in all version

<meta http-equiv="X-UA-Compatible" content="IE=7" />

Also you can check your site with different browser compatibility with this site http://browsershots.org/

I hope this helpful to all……..

Fix Border- radius (CSS3) and Box-shadow for ie7,ie8


HI..
In this article I will explain about how to fix the border radius css in ie7,ie8 and Mozilla.The border radius css is new css it support only for new version.It can support only for ie9 and new version explorer
By using an below file it can support all browser using ie-css3.htc file..

From the below link download the file and copy into your directory..and give the path in css code and write the border radius then it will support for all browser


Your CSS code should like below.....

Mention the file URL in behaviour .. like below
<style type="text/css" >
    
    .greenborder
{
border-radius: 15px 15px 15px 15px;padding: 8px; border: 2px solid #7F9F1A;
behavior: url(ie-css3.htc);
background-color :White ;
box-shadow: 10px 10px 5px #888;
}
    
    .fillborder
{
border-radius: 15px 15px 15px 15px;padding: 8px; border: 2px;
behavior: url(ie-css3.htc);
box-shadow: 10px 10px 5px #888;
}
    
    </style>



<table cellpadding ="0" cellspacing ="0" align="center" width="500" class ="greenborder">
    <tr>
    <td height="80">
    
    &nbsp;
    </td>
    
    </tr>
    </table>
     <table cellpadding ="0" cellspacing ="0" align="center" width="500">
    <tr>
    <td height="80">
    
    &nbsp;
    </td>
    
    </tr>
    </table>
   <table cellpadding ="0" cellspacing ="0" align="center" width="500" class ="fillborder">
    <tr>
    <td height="80">
    
    &nbsp;
    </td>
    
    </tr>
    </table>

i hope this one helpful to all ...




Friday, August 12, 2011

Detect page refresh or F5 press event in asp.net


hi..
In this article u know about to detect refresh button in asp.net...For some case we don’t pass refresh event to any code. By detecting f5 we can easily bypass the code..Its very simple just write the below code in your page ,when you press F5 button it detect its store Boolean value  refresh= true..By using refresh variable we can easily detect f5 wherever in that page....

Also  when upload file using upload control, After uploading when press F5 again its uploading the same file ...by avoiding such a event  You  can check refresh event by using this code..

For an example here i added one button in a page when a press F5 it detect refresh then button event has pass the value...

Just write the code wherever in the page...
Private refreshState As Boolean
Private Refresh As Boolean

 Protected Overrides Sub LoadViewState(ByVal savedState As Object)
        Dim AllStates As Object() = savedState
        MyBase.LoadViewState(AllStates(0))
        refreshState = Boolean.Parse(AllStates(1))
        Refresh = refreshState = Session("ISREFRESH")
    End Sub

    Protected Overrides Function SaveViewState() As Object
        Session("ISREFRESH") = refreshState
        Dim AllStates() As Object = New Object(2) {}
        AllStates(0) = MyBase.SaveViewState
        AllStates(1) = Not (refreshState)
        Return AllStates
    End Function

Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click
        If Refresh = True Then
            Response.Write("hi")
        End If
    End Sub

I hope this one helpful to all…..

Saturday, August 6, 2011

Sorting in datatable


Hi..in this article i will explain about do sorting in datatable.

Intially this type of situation comes after bind the data to grid view or datalist ,if you want
do sorting link ascending or descending order that time again u need to fetch data from the database.Instead of you can follow this method sorting in datatable..

Before bind the data to gridview or datalist.make one copy in session..Then when do sorting use the session data do sorting in datatable and bind gridview again..

Steps to follows...
For an example you have dropdownlist and gridview..
In dropdown list added ascending and descendin..

After bind the data in gridview..By using dropdown we sorting...

Write the below code in dropdown list selected index change...

Dim dt1 as new datable
 dt1 = Session("dtitems") ' Here i copy the data form session to datatable


"Here copied the data to datatable


        Dim dataview As DataView = dt1.DefaultView


        If ddldescen.SelectedIndex = 1 Then
            dataview.Sort = "Number desc"  'Number is column name in datatable,So change the column in descending order in datatable
        ElseIf ddlascend.SelectedIndex = 2 Then
            dataview.Sort = "Number ASC"  'Number is column name in datatable,So change the column in ascending order in datatable
         End If


        DataList1.DataSource = dataview 'Finally i bind the data in datalist
        DataList1.DataBind()

i hope this one helpful to all.....
Post your valuable comments here.......