How to host website in IIS with custom URL

Hello friends,

Recently i need to add website in IIS with custom URL to check third party account sign in. I want to share steps to create website in IIS with all of you to help someone who do it first time.

First you have to check IIS is installed in your machine or not. To confirm it go to Start -> Control Panel -> Programs -> Turn windows features on or off -> Internet Information Services -> Web Management Tools -> check IIS Management Console. Click OK.
IISMgmtConsole

To create website in IIS follow below steps.
-> Go to IIS Manager

IIS Manager

-> Right click on Sites. Select Add Web Sites.

AddWebsite

-> Enter site name and select physical path. Also add Host name you want. Also set App pool.

SiteNameHostName

-> Click on OK.

You have done all. Now, go to browser and type your URL. Enjoy!!!

Error 404.2 ISAPI and CGI list settings restrictions list settings on Web Server

Hello All,

Recently i have got an error 404 for ISAPI and CGI list settings restrictions list settings on Web Server.

To solve this problem we can set this in IIS.
-> Go to IIS manager click on Server Name.
-> Go in ISAPI and CGI Restrictions.
-> Select ASP.Net 4.0 (your .net version).
-> If it has “Not Allowed” then Right click and select “Allow”.

Now check your site the error will gone. To give more idea see below image.
ISAPIandCGIOption

ISAPIandCGIAllow

The GridView ‘gv1′ fired event RowDeleting which wasn’t handled

Hi Friends,

Today, i will discuss about gridview delete command event which returns error sometime like “The GridView ‘gv1′ fired event RowDeleting which wasn’t handled.” and why they return it??

see the below code where I have used delete image button in gridview template field. I have also defined event for OnRowCommand in gridview.



................................
................................
................................
................................









................................
................................
................................
................................



Here is what I am doing in the code-behind:

 protected void gv1_RowCommand(object sender, GridViewCommandEventArgs e)
    {
        if (e.CommandName.Equals("DELETE"))
        {
           .........
           .........

           Operation related to deleting record from gridview and binding record to gridview

           .........
           .........

        }
    }

I am getting below error after clicking on delete button:
gv_deletee

Here is reason for error :-
I am assuming the delete button is in a datagrid. Since the name is ‘delete’, that’s a reserved name and it will trigger the deleting event.

Solution For This Error :-
Either change the name or add a dummy RowDeleting handler.

I have changed the command name of button from “DELETE” to “DELETEITEM” abd it solves the error.

Hope this will help !!!…

Gridview sorting ascending descending image example

Today i want to share Gridview ascending/descending image example with all of you.

To see sorting example visit my previous articles. How to enter ascending/descending image direction in gridview header? is common question for beginners. So, i have prepare one example to show you how you will do this.

In aspx page declare grid view as follow.


            
                
                    
                        
                    
                    
                        <%# Eval("BusinessEntityID")%>
                    
                
                
                    
                        First Name
                    
                    
                        <%# Eval("FirstName") %>
                    
                    
                        
                    
                
                
                    
                        Last Name
                    
                    
                        <%# Eval("LastName") %>
                    
                    
                        
                    
                
                
                    
                        Address
                    
                    
                        <%# Eval("AddressLine1") %>
                    
                    
                        
                    
                
                
                    
                        City
                    
                    
                        <%# Eval("City") %>
                    
                    
                        
                    
                
                
                    
                        Postal Code
                    
                    
                        <%# Eval("PostalCode") %>
                    
                    
                        
                    
                
                
            
        

Now, in cs file add following code at BindData function which is done all job for you. We are adding few lines which is search Linkbutton from gridview Hearder and add image at that place.

            // For Sorting Image
            LinkButton lnkID = (LinkButton)this.gvData.HeaderRow.FindControl("lnkID");
            LinkButton lnkFirstName = (LinkButton)this.gvData.HeaderRow.FindControl("lnkFirstName");

            if (this.gvData_SortBy == lnkID.CommandArgument.ToLower())
            {
                InsertSortImage(this.gvData.HeaderRow.Cells[0]);
            }
            else if (this.gvData_SortBy == lnkFirstName.CommandArgument.ToLower())
            {
                InsertSortImage(this.gvData.HeaderRow.Cells[1]);
            }

Add one more function to insert image in header.

    protected void InsertSortImage(TableCell orderedCell)
    {
        string imgUrl = null;

        if (this.gvData_IsAsc == true)
        {
            imgUrl = "images/desc.gif";
        }
        else
        {
            imgUrl = "images/asc.gif";
        }

        Image img = new Image();
        img.ImageUrl = imgUrl;
        img.BorderStyle = BorderStyle.None;
        orderedCell.Controls.Add(img);
    }

Now, you are ready just add “Images” folder in your project and add two images asc.gif and desc.gif. I am attaching both images here with this article.

descasc

How to retrieve youtube thumbnail image in asp.net

Hi Friends,

Today I will explain how to retrieve thumbnail image from YouTube video in asp.net.

Generally we are embedding a video from youtube to our website dynamically and we need to integrate thumbnail image of that video in our site.

To retrieve thumbnail image from YouTube video we can use YouTube API URL.
see below URL:
“http://img.youtube.com/vi/” + youtubeVideoID + “/default.jpg”

To test above URL replace youtubeVideoID with any YouTube video id like “UMAa148hojo” and run the URL it will show you thumbnail image of video.

Here, I have used default.jpg which shows “120×90″ size default youtube trailer thumbnail image.

If you want bigger image then you can use “0.jpg” instead of “default.jpg”.

If you want other thumbnail image instead of default image then you can specify “1, 2 or 3.jpg”.

See the below example, I have used “MERE BAAP PEHLE AAP” – Trailer and binds different size of thumbnails using asp.net.

Youtube Trailer Thumbnail Images

see below code for asp.net code behind class

protected void Page_Load(object sender, EventArgs e)
    {
        string youtubeVideoID = "UMAa148hojo";
        image0.ImageUrl = "http://img.youtube.com/vi/" + youtubeVideoID + "/default.jpg";
        Image1.ImageUrl = "http://img.youtube.com/vi/" + youtubeVideoID + "/0.jpg";
        Image2.ImageUrl = "http://img.youtube.com/vi/" + youtubeVideoID + "/1.jpg";
        Image3.ImageUrl = "http://img.youtube.com/vi/" + youtubeVideoID + "/2.jpg";
        Image4.ImageUrl = "http://img.youtube.com/vi/" + youtubeVideoID + "/3.jpg";
    }

You will get below images for your code in output.
youtube_thubnails

How to use edit, delete in gridview

Hello Friends,

Today i am sharing one example for gridview edit and delete functionality. Example is for beginners who want to learn gridview edit and delete functionality.

To apply edit, delete functionality in your grid you should follow below steps.
In aspx page declare gridview control and add event OnRowEditing, OnRowUpdating, OnRowCancelingEdit and OnRowDeleting also add DataKeyNames for row value. Now, add CommandField in your grid. In my example i have declare grid as follow.

        
            
                
                    
                        
                    
                    
                        <%# Eval("BusinessEntityID")%>
                    
                
                
                    
                        First Name
                    
                    
                        <%# Eval("FirstName") %>
                    
                    
                        
                    
                
                
                    
                        Last Name
                    
                    
                        <%# Eval("LastName") %>
                    
                    
                        
                    
                
                
                    
                        Address
                    
                    
                        <%# Eval("AddressLine1") %>
                    
                    
                        
                    
                
                
                    
                        City
                    
                    
                        <%# Eval("City") %>
                    
                    
                        
                    
                
                
                    
                        Postal Code
                    
                    
                        <%# Eval("PostalCode") %>
                    
                    
                        
                    
                
                
            
        

In EditItemTemplate you can add textbox, radiobutton or checkbox etc…
In .cs file do following code

    protected void gvData_Editing(object sender, GridViewEditEventArgs e)
    {
        gvData.EditIndex = e.NewEditIndex;
        BindData();
    }

    protected void gvData_Updating(object sender, GridViewUpdateEventArgs e)
    {
        GridViewRow row = gvData.Rows[e.RowIndex];
        int id = 0;
        int.TryParse(e.Keys["BusinessEntityID"].ToString(), out id);

        TextBox txtFirstName = (TextBox)row.FindControl("txtFirstName");
        TextBox txtLastName = (TextBox)row.FindControl("txtLastName");
        TextBox txtAddressLine1 = (TextBox)row.FindControl("txtAddressLine1");
        TextBox txtCity = (TextBox)row.FindControl("txtCity");
        TextBox txtPostalCode = (TextBox)row.FindControl("txtPostalCode");

        DBM.SqlCommandEx sqlCmd = new DBM.SqlCommandEx(
                    String.Format("UPDATE Person.Person" +
                    " SET firstName='{0}', lastName='{1}'" +
                    " WHERE BusinessEntityID = {2}"
                    , txtFirstName.Text, txtLastName.Text, id) +

                    String.Format(" UPDATE Person.Address" +
                    " SET addressLine1='{0}', city='{1}', postalCode='{2}'" +
                    " WHERE addressID = (SELECT addressID FROM Person.BusinessEntityAddress WHERE BusinessEntityID = {3})"
                    , txtAddressLine1.Text, txtCity.Text, txtPostalCode.Text, id)

                    );

        DataTable i = sqlCmd.GetDataTable();

        gvData.EditIndex = -1;
        BindData(); 
    }

    protected void gvData_Deleting(object sender, GridViewDeleteEventArgs e)
    {
        GridViewRow row = gvData.Rows[e.RowIndex];
        int id = 0;
        int.TryParse(e.Keys["BusinessEntityID"].ToString(), out id);

        // Delete Code Goes here Try it yourself

        gvData.EditIndex = -1;
        BindData();
    }

    protected void gvData_CancelingEdit(object sender, GridViewCancelEditEventArgs e)
    {
        gvData.EditIndex = -1;
        BindData();
    }

EditIndex is used to edit the gridview row. It will tell that grid is in edit mode. Default EditIndex is -1 means no row in editmode.

That’s it all done now, you are ready.
I am attaching demo here GridView Edit Delete Example

youtube flash player hide menu

Hello,

Today I have integrated youtube video in my site but it hides the menu and other asp.net controls.

I have just copied the youtube tag from youtube site and paste it into my iframe page.

You know that there is property “z-index” that helps the browsers understand which elements to display in which order. So I have assigned “z-index” but it doesn’t work.

After that I have used wmode parameter in youtube embedded tag and it solves my problem

see below example:
I have used below embedded code in my page


code with wmode parameter


If you can’t specify wmode property in youtube embedded tag then it will take default wmode as opaque. So you need to specify it as transparent and it will solve your problem.

Hope this will help.