Advertisements
RSS

Tag Archives: code

JavaScript: Cookies


A cookie is a variable that is stored on the user’s computer. You can use Javascript to create and retrieve cookie values.

To create a cookie:


function setCookie(sCookieName, sCookieValue)
{
var oCookieExpiryDate = null;
try
{
oCookieExpiryDate = new Date();
if (oCookieExpiryDate == null)
{
return -1;
}
oExpiryDate.setTime(oCookieExpiryDate.getTime() + (1000 * 60 * 60 * 24 * 30)); //30 days
document.cookie = sCookieName + "=" + sCookieValue + "; path=/" + ((oCookieExpiryDate == null) ? "" : "; expires=" + oCookieExpiryDate.toGMTString());
}
catch(e)
{
}
finally
{
}
}

To get the value of a cookie:


function getCookie (sCookieName)
{
try
{
var sCookieNameEQ = sCookieName + "=";
var oCookiesArray = document.cookie.split(';');
for(var i=0;i < oCookiesArray.length;i++)
{
var oCookieItem = oCookiesArray[i];
while (oCookiesArray.charAt(0)==' ')
{
oCookieItem = oCookieItem.substring(1,oCookieItem.length);
}
if (oCookieItem.indexOf(sCookieNameEQ) == 0)
{
return oCookieItem.substring(sCookieNameEQ.length,oCookieItem.length);
}
}
return null;
}
catch(e)
{
}
finally
{
}
}

 

Advertisements
 
Leave a comment

Posted by on October 10, 2012 in Programming

 

Tags: , , , , , , , , , , , ,

ReportViewer Error : Operation is not valid due to the current state of the object


I was getting this error in my ASP.NET application when I try to load a report into the report viewer control. To solve this I used the Reset() method of the report viewer control.



oReportViewer.Reset()
oReportViewer.ProcessingMode = Microsoft.Reporting.WebForms.ProcessingMode.Remote
oReportViewer.Visible = True
oReportViewer.ServerReport.ReportServerUrl = New System.Uri(sReportServiceURL)
oReportViewer.ServerReport.ReportPath = sReportName
oReportViewer.ShowParameterPrompts = False
oReportViewer.ShowDocumentMapButton = False
oReportViewer.DocumentMapWidth = 0
oReportViewer.ShowDocumentMapButton = False
oReportViewer.ShowFindControls = False
oReportViewer.ServerReport.Refresh()

 
Leave a comment

Posted by on September 27, 2012 in Programming

 

Tags: , , , , , , , , , ,

Using Web.config in ASP

I used this code in ASP to read a web.config key value

set xmlDoc=server.CreateObject("Microsoft.XMLDOM")
set xmlappSettings=server.CreateObject("Microsoft.XMLDOM")
set xmladd=server.CreateObject("Microsoft.XMLDOM")
xmlDoc.async="false"
xmlDoc.load(server.MapPath ("web.config"))
set xmlappSettings = xmldoc.GetElementsByTagName("appSettings").Item(0) 
set xmladd = xmlappSettings.GetElementsByTagName("add")
for each x in xmladd 
   ‘Check for the Atrribute Value
   if  x.getAttribute("key") ="RequiredKey" then
          sRequiredKey = x.getAttribute("value")
   end if
next

 
Leave a comment

Posted by on June 9, 2010 in Programming

 

Tags: , , , , , ,

Using ASP.NET Mobile Forms

I wanted to use the normal ASP.NET Forms stuff in a mobile form.

  • Right click on the web site project and select Add new Item

1

  • Select Mobile Web Form. enter a name for the form and click on Add button

2

  • To use a style sheet & a JavaScript file, I added a DeviceSpecific with SupportJavaScript Filter. this is how the HTML code looks like

3 

  • Now I wanted to created some ASP controls. so I added another DeviceSpecific with isHTML32 Filter. this is how the HTML code looks like

4

 

  • One last thing, in order to make those DeviceSpecific Filters to work you need to add the required keys in the web.config file. this is how this would look like

untitled

 
2 Comments

Posted by on February 5, 2010 in Programming

 

Tags: , , , , , , , , , , , , , , ,

GridView: Wrong Fields Order

 

I was working on a GridView that is binding to a custom class collection to display its properties. the fields in the GridView were ordered depending on the order of the properties in the Class. everything was working fine. until I moved the code to a different development environment.

In the new development environment the order of the GridView fields was not as expected. after spending a lot of time trying to fix that. I installed the .NET 2.0 service pack 2 and that solved the problem!!!!

You can download the .NET 2.0 SP2 from here

http://www.microsoft.com/downloads/details.aspx?familyid=5B2C0358-915B-4EB5-9B1D-10E506DA9D0F&displaylang=en

 
Leave a comment

Posted by on January 27, 2010 in Programming

 

Tags: , , , , , , ,

Write to a file using JavaScript


Use this function to write to a file using JavaScript

 

function WriteToFile(sMessage)
{
  try
  {
        var fso, s;
        fso = new ActiveXObject(“Scripting.FileSystemObject”);
        sFile = fso.OpenTextFile(“C:\\logs.txt”, 8);
        sFile.writeline(sMessage);
        sFile.Close();
  }
  catch(err)
  {
        var strErr = ‘Error:’;
        strErr += ‘\nNumber:’ + err.number;
        strErr += ‘\nDescription:’ + err.description;
        document.write(strErr);
  }
}

 
Leave a comment

Posted by on September 9, 2009 in Programming

 

Tags: , , , , , ,

VB.NET Sort Method for a Collection Class


I have a VB.NET collection class EmployeesCollection for an Employee Class that got an Integer Property named Age; I want to create a method (SortByAge) to sort the collection members by Age.

 


This is the EmployeesCollection Class:

 

Imports Microsoft.VisualBasic

Public Class EmployeesCollection
Inherits System.Collections.CollectionBase

Public Sub Add(ByVal tblEmployee As Employee)
' Invokes Add method of the List object to add a widget.
List.Add(tblEmployee)
End Sub

Public ReadOnly Property Item(ByVal index As Integer) As Employee
Get
' The appropriate item is retrieved from the List object and
' explicitly cast to the Widget type, then returned to the
' caller.
Return CType(List.Item(index), Employee)
End Get
End Property

End Class
 


To create the SortByAge method I need a SortHelper Class, This helper Class will include a Function called Compare to compare between the Age values of the employees, the SortHelper Class will be part of the EmployeesCollection Class.

 

 
Private Class AgeSortHelper
        Implements IComparer

        Public Function Compare(ByVal x As Object, ByVal y As Object) As Integer _
             Implements System.Collections.IComparer.Compare
            If x.Age > y. Age Then
                Return 1
            End If

            If x. Age < y. Age Then
                Return -1
            End If

            Return 0
        End Function
    End Class

 


Now we need to create the SortByAge method for the EmployeesCollection Class, in this method we will use the AgeSortHelper to sort the Employees.

 

    Public Sub SortByAge()
        Dim sorter As System.Collections.IComparer = New AgeSortHelper()
        InnerList.Sort(sorter)
    End Sub

 

This is the Final EmployeesCollection Class:

 

Imports Microsoft.VisualBasic

Public Class EmployeesCollection
    Inherits System.Collections.CollectionBase

    Public Sub Add(ByVal tblEmployee As Employee)
        ' Invokes Add method of the List object to add a widget.
        List.Add(tblEmployee)
    End Sub

    Public ReadOnly Property Item(ByVal index As Integer) As Employee
        Get
            ' The appropriate item is retrieved from the List object and
            ' explicitly cast to the Widget type, then returned to the
            ' caller.
            Return CType(List.Item(index), Employee)
        End Get
    End Property

    Public Sub SortByAge()
        Dim sorter As System.Collections.IComparer = New AgeSortHelper()
        InnerList.Sort(sorter)
End Sub
   
Private Class AgeSortHelper
        Implements IComparer

        Public Function Compare(ByVal x As Object, ByVal y As Object) As Integer _
             Implements System.Collections.IComparer.Compare
            If x.Age > y. Age Then
                Return 1
            End If

            If x. Age < y. Age Then
                Return -1
            End If

            Return 0
        End Function

    End Class
End Class

 
Leave a comment

Posted by on August 4, 2009 in Programming

 

Tags: , , , , , , , , ,

 
%d bloggers like this: