pages

Saturday, 23 March 2013

Working with Videos in Grid View Control

One of my friend asked me how do you manage videos in your Asp.Net page. In first shot i said "HTML5". After that one asked me how to display video in GridView Control.
Believe me firstly i was confused about it then i thought about what can we do inside item template to display the videos in our grid. Then first answer came to my mind (HTML5) and i was like "Oh man!!".

This post have no complicated code in it to understand. One simple grid view and Simple HTML5 video tag.
Lets start doing it:

  • Place a asp.net gridview control on your page.
  • Add all the fields from database (Here i am assuming that you are saving link to videos in your database).
  • Use what ever field you want to use for your data (Bound field/Checkbox field etc) but for video column you have to take the ItemTemplate only.



























  • Bind data to your grid. and its done.



P.S. : 

  1. Please Note that HTML5 tags don't work in every browser.
  2. In my case I m using Chrome25.
  3. Its not working in Firefox 13.
  4. For saving video url's in database dont save them using (~/Videos...)
  5. Save directly as (Videos/video.mp4)
  6. Also its not necessary that every file format will run. I tried with wmv, it didnt worked.



Tuesday, 26 February 2013

Substitution Control in asp.net and calling method in .aspx page

Hi All, Today i was just glancing through the toolbox of Visual Studio, Suddenly a control came to my mind SUBSTITUTION control.

I thought to first write about this control only. Actually earlier i was planning to write about working with Nesting the GridView, But now it will be my next post..

So, This substitution control is so simple that people rarely talk about this control but it is very useful when it comes to Calling a function in your .aspx page when you have set some output cache for your page then it will help you for displaying the dynamic content on the cached page.


It is a simple solution for partial page caching for a page where most of the content is cached. In case of using this control in cached page the cached content will remain static until its cache expires but substitution control will fetch fresh data every time page is requested.

This control is basically used in pages which are cached and some part of the page needs to be updated frequently.



Lets have a look on how it works:


Simple One Line Declaration

In this line we are calling a method name DateTimeMethod delared in .aspx.cs file.

Method should meet the following criteria:

  • It should be static
  • It must accept a parameter of type HttpContext
  • It should return a string.



Best part of substitution control is that it doesnt render any markup. It will directly send the output as plain text.Other controls on page aren't accessible to Substitution control.





P.S.  Calling Csharp Methods Directly in aspx page:


One more point to note here is that we can achieve same behaviour by using script tag in aspx page. Example is as follows:




and best part of using this is we don't compulsorily have to use string as return type. We can take int or whatever we want. Given code will work absolutely fine.