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

Type in another Language in Asp.Net TextBox (Google Transliteration )

Hello,

Some time as per client requirement we need TextBox which support different language.

We can do this by using  Google Transliteration.

use below code to achieve this.







<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>



<!DOCTYPE html>



<html xmlns="http://www.w3.org/1999/xhtml">

<head runat="server">

    <title></title>

    

   <script src="https://www.google.com/jsapi" type="text/javascript">

    </script>

    <script language="javascript" type="text/javascript">

        google.load("elements", "1", { packages: "transliteration" });



        function onLoad() {

            var options = {

                //Source Language

                sourceLanguage: google.elements.transliteration.LanguageCode.ENGLISH,

                // Destination language to Transliterate

                destinationLanguage: [google.elements.transliteration.LanguageCode.HINDI],

                transliterationEnabled: true

            };



            var control = new google.elements.transliteration.TransliterationControl(options);

            control.makeTransliteratable(['txtInput']);



        }

        google.setOnLoadCallback(onLoad);

</script>

</head>

<body>

    <form id="form1" runat="server">

    <div>

    <asp:TextBox id="txtInput" runat="server" style="border: 2px solid Blue; height: 200px; margin-left: auto; width: 600px;" textmode="MultiLine"/>



    </div>

    </form>

</body>



</html>



Below is screen shot of my application..


This code support all the language which support by google..

Let me know in case of query.

Enjoy !!

Posted in | 0 comments

How to find text from all tables of SQL Server (Find Specific Text in All Tables of SQL)

Hello,

Create below store procedure first.




Create PROC SearchInAllTable

(

@searchText nvarchar(max)

)

AS

BEGIN



SET NOCOUNT ON

DECLARE @TableName nvarchar(256), @ColumnName nvarchar(128), @searchString nvarchar(110)

CREATE TABLE #FinalOutput (ColumnName nvarchar(370), ColumnValue nvarchar(3630))

SET  @TableName = ''

SET @searchString = QUOTENAME('%' + @searchText + '%','''')



WHILE @TableName IS NOT NULL

BEGIN

    SET @ColumnName = ''

    SET @TableName = 

    (

        SELECT MIN(QUOTENAME(TABLE_SCHEMA) + '.' + QUOTENAME(TABLE_NAME))

        FROM    INFORMATION_SCHEMA.TABLES

        WHERE       TABLE_TYPE = 'BASE TABLE'

            AND QUOTENAME(TABLE_SCHEMA) + '.' + QUOTENAME(TABLE_NAME) > @TableName

            AND OBJECTPROPERTY(

                    OBJECT_ID(

                        QUOTENAME(TABLE_SCHEMA) + '.' + QUOTENAME(TABLE_NAME)

                         ), 'IsMSShipped'

                           ) = 0

    )



    WHILE (@TableName IS NOT NULL) AND (@ColumnName IS NOT NULL)

    BEGIN

        SET @ColumnName =

        (

            SELECT MIN(QUOTENAME(COLUMN_NAME))

            FROM    INFORMATION_SCHEMA.COLUMNS

            WHERE       TABLE_SCHEMA    = PARSENAME(@TableName, 2)

                AND TABLE_NAME  = PARSENAME(@TableName, 1)

                AND DATA_TYPE IN ('char', 'varchar', 'nchar', 'nvarchar')

                AND QUOTENAME(COLUMN_NAME) > @ColumnName

        )



        IF @ColumnName IS NOT NULL

        BEGIN

            INSERT INTO #FinalOutput

            EXEC

            (

                'SELECT ''' + @TableName + '.' + @ColumnName + ''', LEFT(' + @ColumnName + ', 3630) 

                FROM ' + @TableName + ' (NOLOCK) ' +

                ' WHERE ' + @ColumnName + ' LIKE ' + @searchString

            )

        END

    END 

END



SELECT * FROM #FinalOutput

END






Now Run this store procedure from SSMS.




exec SearchInAllTable 'text which need to search'




Enjoy!!!

Posted in | 0 comments