Friday, July 27, 2012

Creating Dynamic Menu Bar C#.Net


Here is the example for the Dynamic Menu creation..
U need to create css for the static and dynamic styles,
Important thing is the menu id , Menu ID should be minimum (maintain around 10 charaters) , I spent lot of time to identify the Issue which created by menu id , I was given over 30+ character which makes effect on total Controls which is available on the page..

private Panel CreateDynamicMenuBar(List<string> Permissions, string GroupName)
    {
        Menu MyMenu = new Menu();
        MyMenu.ID = "menu";
        MyMenu.Orientation = Orientation.Vertical;
        MyMenu.StaticDisplayLevels = 1;
        MyMenu.Width = Unit.Percentage(100);
        MyMenu.StaticMenuStyle.BorderWidth = Unit.Pixel(0);
        MyMenu.StaticMenuItemStyle.HorizontalPadding = Unit.Pixel(0);
        MyMenu.CssClass = "treemenustyle2";
        MyMenu.StaticMenuItemStyle.CssClass = "StaticItem1";
        MyMenu.StaticHoverStyle.CssClass = "StaticHighlight1";
        MyMenu.DynamicMenuStyle.CssClass = "ie8fix";
        MyMenu.DynamicMenuItemStyle.CssClass = "DynamicItem1";
        MyMenu.DynamicHoverStyle.CssClass = "DynamicHighlight1";
        MyMenu.DynamicSelectedStyle.CssClass = "DyanamicSelected1";
        MyMenu.StaticSelectedStyle.CssClass = "StaticSelected1";
        MyMenu.MenuItemClick += new MenuEventHandler(this.Menutasks_SelectedItemChanged);
        MyMenu.Items.Clear();
   
        foreach (var v in Permissions)
        {
            string permissions = v;
            MenuItem item = null;
            item = new MenuItem( permissions );
            item.ToolTip = permissions[1];
            MyMenu.Items.Add(item);
        }
     
        Panel menupannel = new Panel();
        menupannel.Controls.Add(MyMenu);
        return menupannel;
    }

Thursday, July 12, 2012

Response.Redirect vs Server.Transfer

Server.Transfer does a server side transfer.

Response.Redirect does a client side redirect - the server informs thebrowser to redirect.
So here's the flow:


Server.Transfer
1. Client Request Page HelloWorld.ASPX2. Server.Transfer -> Server send a different page to the client3. Client Receives Page still thinking it's HelloWorld.ASPX.4. Client's URL (Address bar) remains HelloWorld.ASPX since the page wassent on the server side and the client doesn't know a different page wassent.


Response.Redirect
1. Client Requests Page HelloWorld.ASPX2. Response.Redirect -> Server sends a HTTP header informing that theuser should redirect. 3. Client sees the redirect notice and requestsAnotherPage.ASPX 4. Server sends AnotherPage.ASPX5. Client's URL (address bar) shows AnotherPage.ASPX
Technically speaking, Server.Trasfer is faster since there 1 lessroundtrip, but you lose the URL of the page. Server.Transfer also allowsfor more flexibilty since you can use HTTPContext.Items to passvariables beteen pages

Thursday, July 5, 2012

.cs files got corrupted?

If your .cs file got currupted then we have one chance to recover those files.

You need to have the assembly dll related to that currupted file which was build previously.
you need to do Disassembler using .Net Reflector


Solution to recover .cs file 
1. Just Download the .Net Reflector and Install. http://www.reflector.net/
2. Open File -> ' Export Assembly source code'

3. In that Export dialogue show the dll related to corrupted file by 'Browse' option and Click 'Start'

Show any other related dll's if required while processing.


Your files will be Generated in the specified 'Output Directory' 


--Thank You

Monday, July 2, 2012

Sorting Alphanumeric


Sorting Alphanumeric:
IComparer interface
public class AlphanumComparatorFast : IComparer
{
    public int Compare(object x, object y)
    {
 string s1 = x as string;
 if (s1 == null)
 {
     return 0;
 }
 string s2 = y as string;
 if (s2 == null)
 {
     return 0;
 }

 int len1 = s1.Length;
 int len2 = s2.Length;
 int marker1 = 0;
 int marker2 = 0;
 while (marker1 < len1 && marker2 < len2)
 {
     char ch1 = s1[marker1];
     char ch2 = s2[marker2];
     char[] space1 = new char[len1];
     int loc1 = 0;
     char[] space2 = new char[len2];
     int loc2 = 0;
     do
     {
  space1[loc1++] = ch1;
  marker1++;

  if (marker1 < len1)
  {
      ch1 = s1[marker1];
  }
  else
  {
      break;
  }
     } while (char.IsDigit(ch1) == char.IsDigit(space1[0]));

     do
     {
  space2[loc2++] = ch2;
  marker2++;

  if (marker2 < len2)
  {
      ch2 = s2[marker2];
  }
  else
  {
      break;
  }
     } while (char.IsDigit(ch2) == char.IsDigit(space2[0]));

     string str1 = new string(space1);
     string str2 = new string(space2);

     int result;

     if (char.IsDigit(space1[0]) && char.IsDigit(space2[0]))
     {
  int thisNumericChunk = int.Parse(str1);
  int thatNumericChunk = int.Parse(str2);
  result = thisNumericChunk.CompareTo(thatNumericChunk);
     }
     else
     {
  result = str1.CompareTo(str2);
     }

     if (result != 0)
     {
  return result;
     }
 }
 return len1 - len2;
    }
}

//Main method
using System;
using System.Collections;

class Program
{
    static void Main()
    {
 string[] highways = new string[]
 {
     "100F",
     "50F",
     "SR100",
     "SR9"
 };
 
 Array.Sort(highways, new AlphanumComparatorFast());
 
 foreach (string h in highways)
 {
     Console.WriteLine(h);
 }
    }
}
Output:
50F
100F
SR9
SR100

How to set selectedIndex of select element using JavaScript



Example:

<input id="AnimalToFind" type="text" />
<select id="Animals">
    <option value="0">Chicken</option>
    <option value="1">Crocodile</option>
    <option value="2">Monkey</option>
</select>
<input type="button" onclick="SelectAnimal()" />
<script type="text/javascript">
    function SelectAnimal()
    {
        //Set selected option of Animals based on AnimalToFind value...
    }
 </script>
function SelectAnimal() {
    var sel = document.getElementById('Animals');
    var val = document.getElementById('AnimalToFind').value;
    for(var i = 0, j = sel.options.length; i < j; ++i) {
        if(sel.options[i].innerHTML === val) {
           sel.selectedIndex = i;
           break;
        }
    }
}

Tuesday, June 26, 2012

Error : Cannot open database requested by the login. The login failed. Login failed for user 'IIS APPPOOL\

Issue : Cannot open database  requested by the login. The login failed. Login failed for user 'IIS APPPOOL\.
This type of issues will get if u connecting to database using Windows Authentication mode you have to give permission individually if u install SQL server in Windows Authentication mode.

If u install  SQL server in window authentication by default If you do not choose mixed authentication at the time of SQL Server installation. However these modes can be changed even after installation of SQL Server.


How to Change Windows Authentication To Mixed Mode In SQL Server:
http://vijayraju-ourworld.blogspot.in/2012/06/change-windows-authentication-to-mixed.html

then restart ur Application if possible restart ur Machine then ur issue will clear

Monday, June 25, 2012

Error : How do I change the default developement environment in Visual Studio

Issue : If u selected VB or any other language as the default lDE, but now u want to change to C# or any other,
then proceed the following steps.


1. Choose Tools -> Import and Export Settings...
2. Select Reset All Settings and click Next
3. Select whether you would like to save the current settings and click Next
4. Select the settings you want to use and click Finish