Search This Blog

Friday, May 27, 2016

WebForms UnobtrusiveValidationMode requires a ScriptResourceMapping for 'jquery'. Please add a ScriptResourceMapping named jquery(case-sensitive).

Error in 2012 VS when using validation control :

Server Error in '/it' Application.

WebForms UnobtrusiveValidationMode requires a ScriptResourceMapping for 'jquery'. Please add a ScriptResourceMapping named jquery(case-sensitive).

Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.InvalidOperationException: WebForms UnobtrusiveValidationMode requires a ScriptResourceMapping for 'jquery'. Please add a ScriptResourceMapping named jquery(case-sensitive).

Source Error:

An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.

Stack Trace:


[InvalidOperationException: WebForms UnobtrusiveValidationMode requires 
a ScriptResourceMapping for 'jquery'. Please add a ScriptResourceMapping 
named jquery(case-sensitive).]
   System.Web.UI.ClientScriptManager.EnsureJqueryRegistered() +2170706
   System.Web.UI.WebControls.BaseValidator.RegisterUnobtrusiveScript() +10
   System.Web.UI.WebControls.BaseValidator.OnPreRender(EventArgs e) +9576593
   System.Web.UI.Control.PreRenderRecursiveInternal() +83
   System.Web.UI.Control.PreRenderRecursiveInternal() +168
   System.Web.UI.Control.PreRenderRecursiveInternal() +168
   System.Web.UI.Control.PreRenderRecursiveInternal() +168
   System.Web.UI.Control.PreRenderRecursiveInternal() +168
   System.Web.UI.Page.ProcessRequestMain(Boolean 
includeStagesBeforeAsyncPoint,Boolean includeStagesAfterAsyncPoint) +974

Solution:
Add in web.config :

 <appSettings>
      <add key="ValidationSettings:UnobtrusiveValidationMode" value="None" />
 </appSettings>


Tuesday, May 17, 2016

Differences between Hash table and Dictionary.



Differences between Hash table and Dictionary
Sno.
Dictionary
Hash table
1
It returns error if we try to find a key which does not exist.
It returns null if we try to find a key which does not exist.
2
It is faster than a Hashtable because there is no boxing and unboxing.
It is slower than dictionary because it requires boxing and unboxing.
3
Only public static members are thread safe.
All the members in a Hashtable are thread safe.
4
Dictionary is a generic type which means we can use it with any data type.
Hashtable is not a generic type.

What is Hashtable ?

Hashtable optimizes lookups. It computes a hash of each key you add. It then uses this hash code to look up the element very quickly. It is an older .NET Framework type. It is slower than the generic Dictionary type.

A hash table is made up of a mapping function and an array. The array contains your data, while the mapping function is used to assign numerical values (keys) to the data. This helps in categorizing the data, which speeds up search times when you search for it.

using System.Collections;
using System;
class Example
{
    static void Main()
    {
                Hashtable hashtable = new Hashtable();
                hashtable [1] = "One";
                hashtable [2] = "Two";
                hashtable [3] = "Three";
                foreach (DictionaryEntry entry in hashtable)
                {
                    Console.WriteLine("{0} : {1}", entry.Key, entry.Value);
                }
    }
}

Output:
3: Three
2: Two
1: One

HashTable Method()

using System.Collections;
using System;
class Example
{
static Hashtable GetHashtable()
    {
                // Creating a simple hashtable called hashtable.
                Hashtable hashtable = new Hashtable();
                hashtable.Add("chandra", 10);
                hashtable.Add("prakash", 11);
                hashtable.Add("vipin", 12);
                return hashtable;
   }
static void Main ()
{
Hashtable hashtable = GetHashtable ();
Console.WriteLine(hashtable.ContainsKey (“chandra”));
}

Output:

True

Saturday, May 14, 2016

Example of Dictionary Class

A Dictionary class is a data structure that represents a collection of keys and values pair of data. The key is identical in a key-value pair and it can have at most one value in the dictionary, but a value can be associated with many different keys.
This class is defined in the System.Collections.Generic namespace, so you should import or using System.Collections.Generic namespace.

Dictionary<TKey,TValue>

TKey - The type of the keys in the dictionary.
TValue - The type of the values in the dictionary.

Input Occupancy String format:
Room_Adult_Children_Age  : 1_2_1_10  [room always in string 1]
1_2_1_10 ; 1_2_1_8   or 1_2_1_10  ; 1_2_1_8  ; 1_2_1_5 
Output: 2_1_2_10_11
Input: 1_1_0_-1; 1_1_0_-1
Output: 2_1_0_-1
Input: 1_2_2_6_8  ; 1_2_2_4_6  ; 1_2_2_6_9 
If you want to search for 2 single room with 2 adult and 0 child you pass the occupancy like that:
Input: 1_2_0_-1 ; 1_2_0_-1



If 2 or 3 room then Input Occupancy string format:

Scenario 1: Search for 1 Adult
If you want to search for 1 single room with 1 adult and 0 child you pass the occupancy like that: Input: 1_1_0_-1
Where -1 stands for an age of an adult which is not required so we pass it -1.

Scenario 2: Search for 1 Adult and 2 Children
If you want to search for 1 single room with 1 adult and 2 child you pass the occupancy like that:
Input: 1_1_1_10;1_1_1_11

 where 10 stand for the first age of the first child and 11 stands for the second age of the child.

Scenario 3: Search for 2 rooms one for 1 Adult and 0 Children and the Second for 2 Adults
If you want to search for 2 rooms with 1 adult and 0 children and another room for 2 adults and 0 children you pass them like that:
Input: 1_1_0_-1;1_2_0_-1

Output: 1_1_0_-1;1_2_0_-1

Scenario 4: Search for 2 rooms for the same 1 Adult and 0 Children.
It will be like that

Scenario 5: Search for 3 rooms for the same 2 Adult and 2 Children.
It will be like that
Output: 3_2_2_6_8_4_6_6_9
Scenario 6: Search for 2 Adult 0 Children
Output: 2_2_0_-1


using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Text.RegularExpressions;

namespace WindowsFormsApplication1
{
    public partial class Form2 : Form
    {
        public Form2()
        {
            InitializeComponent();
        }

        public string GroupOccupancy(string occupancy)
        {
            string abc = "";

            string[] arrOccupancy = occupancy.Split(';');
            List<string> objage = new List<string>();

            /*The Dictionary type provides fast lookups with keys to get values. With it we use keys and values of any type, including ints and strings.*/

            Dictionary<object, int> DifferentCarcategory = new Dictionary<object, int>();            

            foreach (Object obj in arrOccupancy)
            {
                /*ContainsKey method. It returns true if the key was found.*/
                string sssdd = Convert.ToString(obj).Substring(0, 5);
                //sssdd = Regex.Replace( "@"+sssdd , "@\\s*[\\d]+?_", "");
                if (!DifferentCarcategory.ContainsKey(sssdd))
                {
                    int totallength = Convert.ToString(obj).Length;
                    String age = Convert.ToString(obj).Substring(5, totallength - 5);
                    objage.Add(age);

                    DifferentCarcategory.Add(sssdd, 1);
                }

                else
                {
                    DifferentCarcategory[sssdd]++;

                    int totallength = Convert.ToString(obj).Length;
                    String age = Convert.ToString(obj).Substring(5, totallength - 5);
                    objage.Add(age);

                }
            }

            /* use foreach syntax and KeyValuePair generics in the foreach loop. With collections like Dictionary, 
             * we must always know the value types. With each KeyValuePair, there is a Key member and Value member.*/

            foreach (string kvp in DifferentCarcategory.Keys)
            {
                string strkv = kvp;
                if (Convert.ToInt32(DifferentCarcategory[kvp]) == 1)
                {
                    abc = abc + ";" + kvp;
                }
                else
                {
                    /*Regex.Replace static method with a string replacement.The "\d" metacharacter matches digit characters.  */
                    abc = abc + ";" + Regex.Replace(kvp, "^[\\d]*?_", Convert.ToString(DifferentCarcategory[kvp]) + "_");
                }
            }
            int spiltindex = 0;
            abc = abc.Trim().Trim(';');
            String sssnew = "";
            string xxxx = "";
            foreach (string kvp in objage)
            {
                if (!abc.Contains(";"))
                {
                   
                   abc = abc + kvp;
                }
                else
                {

                    sssnew = sssnew + abc.Split(';')[spiltindex] + kvp + ";";
                    
                }
                spiltindex++;
            }

           //this condition for no child case in this case only pass (-1) one time in string.
            xxxx = Convert.ToString(abc).Substring(3, 2);
            if (xxxx == "_0")
               abc = Convert.ToString(abc).Substring(0, 8);
            else
            
            abc = String.IsNullOrWhiteSpace(sssnew) ? abc : sssnew;
            abc = abc.Trim().Trim(';');
            return abc.ToString();

        }

        private void button1_Click(object sender, EventArgs e)
        {
            label1.Text = GroupOccupancy(textBox1.Text);
        }
    }
}