Triggering onClick Event from JavaScript Using Jquery.

Hello Friend's,

In one of my application I need to call 'Save' button click from Javascript.

Below is approach which I have used to call click event of 'Save' button.


$($get("id_ofsavebutton")).click();

More you can read about this click Events at
http://api.jquery.com/click/

We can also bind this click event css class.

Example :-

$(".buttonclass").click();

Posted in | 0 comments

NHibernate.MappingException: Could not compile the mapping document

Error Message

NHibernate.MappingException: Could not compile the mapping document: Nhibernate.
User.hbm.xml ---> NHibernate.MappingException: persistent class Nhibernate.User,
 Nhibernate not found ---> System.TypeLoadException: Could not load type 'Nhiber
nate.User' from assembly 'NHibernate, Version=1.2.0.3002, Culture=neutral, Publi

cKeyToken=aa95f207798dfdb4'.

Solution

This error message point to that the compiler does not know the Nhibernate.User class. 

You should check if you have deployed and referred your assembly correctly. 

Also need to check if you have included the correct name space.


Hope this will help you.


Posted in | 0 comments

Call Stored Procedure from Entity Framework


First Create an edmx file.

Double click your edmx file and right click your model,Choose Function Import In the pop-up dialog,

Choose the SP that you want to import as a function.

Now you can use it through the database Context like below.



using (EntityContext ec = new EntityContext())

{

    ec.StoredProcdure here(Parameters);

}


You can also refer below articles for same.

For Database First / Model First you can set up EF to call the SPs automatically:

http://www.asp.net/web-forms/tutorials/getting-started-with-ef/the-entity-framework-and-aspnet-getting-started-part-7

For Code First you have to call them manually:

http://www.asp.net/mvc/tutorials/getting-started-with-ef-using-mvc/advanced-entity-framework-scenarios-for-an-mvc-web-application

Posted in | 0 comments

how to check Null (isDBNull) in C# Data table and Empty string.

how to check Null (isDBNull) in C# Datatable

IsNull method of the DataRow is use to check null value.

Example



     foreach (DataRow row in table.Rows)
       {
           if (row.IsNull("id"))
           {
               Response.Write("success");
           }
       }

Similer IsNullOrEmpty method is use to check string value null or empty.

Example



  public static void Main() 
    {
    string s1 = "abcd";
    string s2 = "";
    string s3 = null;

    Console.WriteLine("String s1 {0}.", Test(s1));
    Console.WriteLine("String s2 {0}.", Test(s2));
    Console.WriteLine("String s3 {0}.", Test(s3));
    }

    public static String Test(string s)
    {
    if (String.IsNullOrEmpty(s)) 
        return "is null or empty";
    else
        return String.Format("(\"{0}\") is neither null nor empty", s);
    }

Posted in | 0 comments

AddMvc() method not found.

Hello,

Many developer do faces this problem during development.

Here some guideline to resolve this error.

1. On VS 2015, Tools >> Options >> Nuget Package Manager >> Package Sources, add https://www.myget.org/F/aspnetvnext/

2. Implemention should be as shown below.



using Microsoft.AspNet.Mvc;

using Microsoft.AspNet.Routing;

using Microsoft.AspNet.Security.DataProtection;

using Microsoft.Framework.ConfigurationModel;



namespace Microsoft.Framework.DependencyInjection

{

  public static class MvcServiceCollectionExtensions

  {

    public static IServiceCollection AddMvc(this IServiceCollection services, IConfiguration configuration = null)

    {

      ConfigureDefaultServices(services, configuration);

      services.TryAdd(MvcServices.GetDefaultServices(configuration));

      return services;

    }



    private static void ConfigureDefaultServices(IServiceCollection services, IConfiguration configuration)

    {

      services.AddOptions(configuration);

      services.AddDataProtection(configuration);

      services.AddRouting(configuration);

      services.AddContextAccessor(configuration);

      services.Configure<RouteOptions>(routeOptions =>

                          routeOptions.ConstraintMap

                            .Add("exists",

                               typeof(KnownRouteValueConstraint)));

    }

  }

}





For more this code refer below link
https://github.com/aspnet/Mvc/blob/27432d94530405f424e9015c8c5311907bd48b3f/src/Microsoft.AspNet.Mvc/MvcServiceCollectionExtensions.cs

3. If the executing request is a POST then it will try to find a method RandomSponsor acceptimg HttpPost. If make sense, you could remove HttpGet and that should do the trick.
This can also happen if you have many layers of calls that start with a POST (I had an action returning a view returning a partial view calling RenderAction), then the call to RenderAction will still look for a POST method.

Hope this will help you.

Posted in | 0 comments