Advertisements
RSS

Tag Archives: beginner

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: , , , , , , , , , , , ,

Updating Select Options using JQuery


So you implemented a webservice that return an ArrayList to update the Select Option.


Public Shared Function UpDateSelectList(ByVal sThemeID As String) As ArrayList


You can use the jQuery $.ajax to call the webservice


$.ajax({
type: "POST",
url: swebserviceURL,
data: oData,
contentType: "application/json; charset=utf-8",
dataType: "json",
success: jsGetArrayListSucess,
failure: function (response)
{
alert("An error was encountered");
}
});


In the callback function you need go through the array list to create an option item and add it to the Select Options


function jsGetArrayListSucess(response)
{
try
{
var DictionaryItems = response.d;
if (DictionaryItems == null || typeof (DictionaryItems) != "object") {
return;

}

var myDropDownList = $get('SelectList');
myDropDownList.options.length = 0;
myDropDownList.options[0] = new Option("Select ", 0);
for (var i = 0; i < DictionaryItems.length; ++i)
{
myDropDownList.options[myDropDownList.options.length] = new Option(DictionaryItems[i].Text, DictionaryItems[i].Value);
}

}
catch (err)
{

}
finally
{

}
}

 
Leave a comment

Posted by on March 3, 2011 in Programming

 

Tags: , , , , ,

Great website for Icons


Looking for icons to your applications:

I highly recommend this site for icons

http://findicons.com/

 
Leave a comment

Posted by on February 25, 2011 in General

 

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: , , , , , ,

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: , , , , , , , , ,

C#: Bind a DropDownList to IDictionary using AjaxPro

Implement an AjaxMethod to return IDictionary object

 

[AjaxPro.AjaxMethod]

public IDictionary AjaxGetIDictionary()

{

//Prepare the IDictionary object

}

– Use JavaScript to request the AjaxMethod AjaxGetIDictionary

MyAjaxClass. AjaxGetIDictionary (jsAjaxGetIDictionary_Callback);

– In the JavaScript function jsAjaxGetIDictionary_Callback add the IDictionary items to the DopDownList

function jsAjaxGetIDictionary (response)

{

     try

    {

         var DictionaryItems= response.value;

         if (DictionaryItems == null || typeof(DictionaryItems) != “object”)

        {

               return;

         }

         var myDropDownList = document.getElementById(“myDropDownList”);

         myDropDownList.options.length = 0;

         for (var i = 0; i < response.value.length; ++i)

         {

             myDropDownList.options[myDropDownList.options.length] = new Option(response.value[i].Value,response.value[i].Key);

           }

    }

    catch(e)

   {

   }

}

 
Leave a comment

Posted by on May 1, 2009 in Programming

 

Tags: , , , , , , , , ,

C#:Using Dictionary as DropDownList Data Source

I have IDictionary Object called ListOptions. To use it as the data source for an ASP.NET DropDownList called objDropDownList:

 

objDropDownList.DataSource = ListOptions;

objDropDownList.DataTextField = “Value”;

          objDropDownList.DataValueField  = “Key”;

          objDropDownList.DataBind(); 

 

 

 

 
Leave a comment

Posted by on March 31, 2009 in Programming

 

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

 
%d bloggers like this: