Wednesday, June 19, 2013

Delegates in C#

Delegates are pointer toward a function or method.It solved the decoupling problem.

For exampling : when you go to marriage the representative welcomes you and tells someone (References) to look after you. Due to this he easily manage all the guest.

Wouldn’t it be nice to have a delegate that could refer to more than one function at once and invoke them
simultaneously? This would allow the client application to have multiple “listeners” and notify the listeners all
at once when something happens.
In fact, delegates do have this functionality, but you’re more likely to see it in use with .NET events.
Events, which are described in the next chapter, are based on delegates but work at a slightly higher level.
In a typical ASP.NET program, you’ll use events extensively, but you’ll probably never work directly with
delegates.


There are four step to create delegates :-
  1. Declare
  2.  Create
  3. Pointer
  4. Invoke
   public delegate int Pointertoaddfun(int i, int y);
    private int add(int x,int y)
    {
        return x + y;
    }
    private int sub(int x, int y)
    {
        return x + y;
    }
 
    public Pointertoaddfun getpointer(int dir)
    {
        Pointertoaddfun objpoiter=null;
        if (dir == 1)
        { objpoiter = add; }
        if (dir == 2)
        { objpoiter = sub; }
    }

    To watch video : -http://www.youtube.com/watch?v=3ckXHImXMiU

Tuesday, June 18, 2013

Trigger in Sql Server

Trigger is a logic which executes on the tables after or before when the insertion, deletion and updation query executes. 

There are two type of trigger
  1. Instead of trigger
  2. After Trigger

Instead of trigger : - It fire before the insert/Update/Delete executes on table.

After Trigger : It fires After insert/delete/update command executes on table.

 Lets Start Understanding the use of trigger in sql server -
First we Create trigger : - this one is after trigger

 
CREATE Trigger tblUpdate   
On tblemp   
After Insert,Delete, Update   
As Begin   
   
Declare @Oldvalues nvarchar(50)   
Declare @newvalues nvarchar(50)   

   
--Fetch inserted value   
Select @newvalues=Customername from inserted   
--fetch deleted value   
   
Select @Oldvalues=Customername from deleted   
   
insert into tblaudit(LastUpdated,Oldvalues,newvalues)   
values(getdate(),@Oldvalues,@newvalues)   
   
End   


Description of Used word in trigger : -
tblUpdate - Trigger Name
tblemp     - Table name on which trigger will fire.
Inserted  - When any insert command executes it will store the current value.

Deleted   - When any delete command excutes it will store the deleted data.


Here i have created two table one is tblemp and tblaudit
Table tblaudit


CREATE TABLE [dbo].[tblaudit](
    [LastUpdated] [datetime] NULL,
    [Oldvalues] [nvarchar](50) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
    [newvalues] [nvarchar](50) COLLATE SQL_Latin1_General_CP1_CI_AS NULL
) ON [PRIMARY]


Table tblemp

CREATE TABLE [dbo].[tblemp](
    [CustomerID] [int] IDENTITY(1,1) NOT NULL,
    [Customername] [nvarchar](50) COLLATE SQL_Latin1_General_CP1_CI_AS NULL
) ON [PRIMARY]


When any insert update delete command executes trigger will fire automatically..

Note : First create table then trigger.
Watch Video click here

Monday, June 17, 2013

405 - HTTP verb used to access this page is not allowed.

The HTTP verb POST used to access path '/html5demos/post.html' is not allowed.

When you tried to work on html page in Visual studio sometime it fire above error.

<!DOCTYPE html>
<html>
<head>
    <title>Untitled Page</title>
</head>
<body>
    <form name="form" id="form1" method="post" action="post.html" target=_self>
    <input type="text" id="text2" name="text2"  />
    <input type="text" id="Text1"  />
    <input type="submit" name="Submit" value="Submit" />
  
    </form>
</body>
</html>

Solution

Problem : File type is not registred in IIS amp setting. Http POST , HEAD are respond with 405 error.

1.GO to Control Panel "Administrative Tools" --> IIS
2.Select The Website and select handler mapping
3.Add Script map
Request Path Should Be " .Htm "
or ".html"
Select this Path  C:\Windows\System32\inetsrv\asp.dll

Name  what ever u can 

After this click on Request Restriction 
 Mapping  :  "Invoke handler only if request is mapped to :" 
check "file" 

Verbs :  "All Verbs"

In the last Click Okay OK

Hope it will work fine... 


Friday, June 14, 2013

Saturday, June 1, 2013

Upload Image through FCK Editor Asp.net

Upload Image through FCK Editor Asp.net it always throws the some issue :-
When trying to upload images through FCK Editor tool inside an aspx page it throws an  error[XML 403 path Error].
To Fix the issue we have to configure manually.

STEP-I :
File Path  :  fckeditor/fckconfig.js
Previously :
var _FileBrowserLanguage    = 'asp' ;  // asp | aspx | cfm | lasso | perl | php | py
var _QuickUploadLanguage    = 'asp' ;  // asp | aspx | cfm | lasso | perl | php | py

We have to change 'asp' to 'aspx'

STEP-II
File Path  :  fckeditor\editor\filemanager\connectors\aspx\config.ascx
Previously :
           Change-1 : Enabled = CheckAuthentication();
                       
                          Change-2 : UserFilesPath = "~/upload/";
           Change-3 : UserFilesAbsolutePath = "C:\\upload\\";
                            
Chnage -1 : change it to Enable = true;
Change -2 : change the folder name in which you want to store the uploaded image.
Change -3 : change the absolute path of the folder in which you want to store the uploaded image.