Tuesday, June 24, 2008

Today Badly java script error

Today, I've got badly Java script error in my work project. I was trying to get cookie value from Java script file. I need to explain more. The project is need dynamic menu.
That menu is created by when u create new page. that page should be added to menu list automatically. I tried to get cookie value like that - ( here we are some coding -

private void MenuList()
{
List menu_list = MenuController.GetMenuList();
List First_list = new List();
List Second_list = new List();
List Third_list = new List();

string strMenu = string.Empty;

if (menu_list.Count > 0)
{
for (int i = 0; i < menu_list.Count; i++)
{
if (menu_list[i].ParentID == Guid.Empty)
{
// find second level menu
Second_list = GetSubMenu(menu_list, menu_list[i].MenuID);

// print out the first level with
  • closing tag if second list count = 0; else print out the first level without
  • closing tag
    if (Second_list.Count > 0)
    {
    string strSecondLevel = string.Empty;

    //print out the first level
    //strMenu += "
  • " + menu_list[i].Name + "";
    strMenu += "
  • " + menu_list[i].Name + "";

    HttpCookie MyCookie = HttpContext.Current.Request.Cookies["menu"];
    if (MyCookie == null)
    {
    MyCookie = new HttpCookie("menu");
    }

    // open the second level
    strMenu += "
      ";

      for (int j = 0; j < Second_list.Count; j++)
      {
      //remove second level list from main list
      for (int count = 0; count < menu_list.Count; count++)
      {
      if (Second_list[j].MenuID == menu_list[count].MenuID)
      {
      menu_list.RemoveAt(count);
      i--;
      }
      }

      // find third level menu
      Third_list = GetSubMenu(menu_list, Second_list[j].MenuID);
      if (Third_list.Count > 0)
      {
      // print out the second level without closing
    • tag
      //strMenu += "
    • " + Second_list[j].Name + "";
      strMenu += "
    • " + Second_list[j].Name + "";

      // open the third level
      strMenu += "
        ";

        foreach (Menus m3 in Third_list)
        {
        // print out the third level
        //strMenu = "
      • " + m3.Name + "
      • ";
        strMenu = "
      • " + m3.Name + "
      • ";

        //remove third level menu from the main list
        for (int c = 0; c < menu_list.Count; c++)
        {
        if (m3.MenuID == menu_list[c].MenuID)
        {
        menu_list.RemoveAt(c);
        i--;
        }
        }
        }

        //close the third level
        strMenu += "
      ";
      //close the second level
      strMenu += "
    ";
    // close the first level
    strMenu += "
  • ";

    int index2 = Second_list.IndexOf(Second_list[j]);
    Second_list.InsertRange(index2 + 1, Third_list);
    }
    else
    {
    // print out the second level
    for (int m = 0; m < Second_list.Count; m++)
    {
    //strMenu += "
  • " + Second_list[j].Name + "
  • ";
    strMenu += "
  • " + Second_list[j].Name + "
  • ";
    }
    // close the second level
    strMenu += "";
    // close the first level
    strMenu += "";

    int index1 = menu_list.IndexOf(menu_list[i]);
    menu_list.InsertRange(index1 + 1, Second_list);

    }
    }
    }
    else
    {
    //strMenu += "
  • " + menu_list[i].Name + "
  • ";
    strMenu += "
  • " + menu_list[i].Name + "
  • ";
    }
    }
    }

    navigationMenuList.InnerHtml = strMenu;
    }
    }

    In above code has bold sentence. that sentece is trying to get cookie value from anchor tag on click event. I have no idea yet. :( BAD Day

    No comments: