Blogs

Friday,27 November,2009 3:16 PM
Using the server side Page.Validate() and Client Side Page_ClientValidate() , we can validate a group of controls conditionally. For eg. i just need to validate some fields only when a checkbox is checked. Both Page.Validate() and Page_ClientValidate() allows to pass a validation group , So we group a set of controls with a validation group and calls this validation functions in both client & server side only on the required validation condition

Server Side



protected void btnSubmit_Click(object sender, EventArgs e)
{
if(cbValidate.Checked)
{
//validate
Validate("vgSubmit");
}
if (!IsValid) return;
lblMsg.Text = "Passed validation";
}



ClientSide


function CheckValidation() {
var cbValidate = document.getElementById('<%=cbValidate.ClientID %>');
var flag = true;
if (cbValidate.checked) {
if (!Page_ClientValidate("vgSubmit"))
flag = false;
}
else {
Page_ClientValidate("vgDummy")
}
return flag;

}



Download Code

Thursday,24 September,2009 12:26 PM

In asp.net 2.0 we used Context.RewritePath() or other URL rewrite modules. With asp.net 3.5 its easy to do. I did it for my blog for better SEO.

      • Add reference to system.Web.Routing
        Add System.Web.Routing.UrlRoutingModule http module to web.config
        Implement an IRouteHandler
        Registering routes in global.asax

I am going to rewrite blogs/Posts/{BlogPostID}/{*BlogPostTitle}

I implemented a generic IRouteHandler , it will copy url parameters( eg: BlogPostID,BlogPostTitle ) to http context item collection, so i can URL rewrite any page , without modifying IRouteHandler implementation.



using System;
using System.Web;
using System.Web.Routing;
using System.Web.Compilation;
using System.Web.UI;
public class SiteRouteHandler : IRouteHandler
{
//30 june 2009 Priyan R

public IHttpHandler GetHttpHandler(RequestContext requestContext)
{
Page page;
page = BuildManager.CreateInstanceFromVirtualPath(PageVirtualPath, typeof(Page)) as Page;
foreach (var item in requestContext.RouteData.Values)
{
HttpContext.Current.Items["qparam." + item.Key] = item.Value;
}
return page;
}
public string PageVirtualPath { get; set; }
}

In global.asax added


       

routes.Add(
"BlogPost",
new Route("Blogs/Posts/{BlogPostID}/{*BlogPostTitle}",
new SiteRouteHandler() { PageVirtualPath = "~/Blogs/Details.aspx" })
);


So in Details.aspx I can read the parameters



Context.Items["qparam.BlogPostID"].ToString()
Context.Items["qparam.BlogPostTitle"].ToString()

Check the code.


Download Code

Wednesday,26 August,2009 6:27 PM
Almost all people might have loved someone in their life..To say something about my love..
I have experienced it three times..but still I dont know exactly what this love thig is
..it made me laugh and cry at the same time...still i am in search of love..
its such a feeling inside us for someone..makes us feel alive..and we get crazy about it..
how that happens is beyond my thinking..it just happens..
I had felled into love with three..but that was incomplete..does that make any sense??he he
of course yes..its always valuable and such an ever memorable feeling to me..
My love is true..always..

I still remember those school days..I didnt get to know that I was in love with someone..
those four years she was with me..After I left my school I got to know how much I miss
her in my life..I believe she would have felt the same what I did..But dont know what to say..
sense of responsibility to my family or something else pushed me back to concentrate
in my studies more..and that relationship stopped when I left my 10th std and joined
plus2..slowly I started trying to forget her..after few days I met another girl..
This time I couldnt stop myself from not loving that girl..I started thinking a lot
about her..what a crap!!I started dreaming too..but , she was not thinking like I did..
hell it took me into a helpless situation..but I recovered from it very soon..
she was not meant to be mine..

And the third one..this time ,I was more carefull and had a clear idea about my wish..
she was so close..and I was very comfortable with her..she enjoyed my friendship..
but she was not in love with me..I dont know what went wrong this time..
she was mistaken or me??I didnt force her or anyone..
coz I believe ,every one has the right to choose someone whom they want to love..
we should not compromise in case of love..it has to happen inside us..otherwise no use..
now I am not feeling to love anyone..just because it cant be made..
hopefully everything will come out to be fine..
and one day i will get my real love ..yes ..I am waiting for that..:)

( For this post i am really grateful to my friend Praseetha, She edited my story in a poet style :) )
Wednesday,12 August,2009 2:21 PM
Download Code

A simple class that can be used to parse rss feed, Check the code attached it will display my twitter updates by parsing the rss feed using the class.


using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Xml.Linq;
namespace RssFeed
{

//12-aug-2009 Priyan R
public class RssParser
{
public RssParser()
{
Items = new List<RssItem>();
}
public RssParser(string url):this()
{
URL = url;
}
#region Methods
public void Parse()
{
XDocument doc = XDocument.Load(URL, LoadOptions.None);
Items = (from t in doc.Descendants("item")
select new RssItem()
{
Title = t.Element("title").Value,
Description = t.Element("description").Value,
Link = t.Element("link").Value

}
).ToList();

}
#endregion
#region properties
public string URL { get; set; }
public List<RssItem> Items { get; set; }
#endregion
}
#region RSS Item Class
public class RssItem
{
public string Title{ get; set; }
public string Description { get; set; }
public string Link { get; set; }
}
#endregion
}
Friday,12 June,2009 12:35 PM
Often SelectCountMethod may be int or long so check the type in object datasource Selected event and store the value in ViewState or a variable so it can be used in the page

protected void odSource_Selected(object sender, ObjectDataSourceStatusEventArgs e)
{
if (e.ReturnValue.GetType() == typeof(Int32))
{
ViewState["TotalCount"] = e.ReturnValue;
}
}
Sunday,10 May,2009 2:50 PM
I moved my websites to a new VPS hosting.For the last 6 months I was managing my own server. here in my place its not trusty ISP problems/Power/Cable , so I am leaving it.
For the last two weeks I was experimenting running windows in virtual machine inside mosso-rackspace cloud using QEMU, Mosso is great but currently they provide only linux , surely they will come with windows,

Now I am using VPS by http://www.infinitelyvirtual.com/.They are not well known, but I trust them. Their plans are cheap and good, 19.99$ 512mb 10gb space 500 GB monthly data transfer. They are using vmware based virtualization.
Sunday,10 May,2009 11:42 AM
Rack space cloud is a very good service with low price. Good customer support, i always got chat session with customer support very soon. They currently provide Linux cloud server only. I am waiting for windows cloud server.

I installed windows 2003 in QEMU , i was not able to Get the KQEMU accelaration layer working. So performance was really poor,


Installation story (Installing 32 bit windows 2003)....


First i created an ubuntu 8.04.2 LTS (hardy) cloud server.

1. Update package list

apt-get update
apt-get upgrade

2. Install QEMU

apt-get install qemu

2. Install X Server

aptitude install xorg

3. Redirect X Display to our system

This was the one main problem i faced. I 'X' forwarded the display to windows pc running XMing. It was really slow.. It took abt 50-100MB data transfer to show the initial windows loading screen.. Took long time to display the screen.. So it is impossible to install windows in this way.

I found a solution X11 VNC

4. Install X11 VNC

apt-get install x11vnc

apt-get install xvfb

Create password file


x11vnc -storepasswd

5. Start X11 VNC create option (will automatically create a display)

x11vnc -usepw -create


6. Connect to X11 VNC From windows using TightVNC


7. Download windows 2003 ISO ( i used windows 2003 trial)


8. Create QEMU hdd image file


qemu-img create win2003.img 20G


9.Install windows

Run qemu with win 2003 iso as cdrom

qemu -m 256 -boot d -cdrom win2003.iso -hda win2003.img -localtime



Problems faced


32 bit windows 2003 installation stuck at installing devices screen , but on restarting once it worked fine.


NetWorking


I was not able setup TAP network working. I used user mode networking with port forwarding option

I run this to forward 3389 port for remote desktop , and 80 for IIS

qemu -hda win2003.img -m 256 -localtime -net nic,model=rtl8139 -net user -redir tcp:3389::3389 -redir tcp:80::80



Installing 64 bit Windows 2003


The qemu version we get with apt-get will not work with win 2003 64
I got stuck "Starting windows" while installing
http://qemu-forum.ipi.fi/viewtopic.php?f=9&t=4906


I installed QEMU 0.90 from source , we need gcc 3.x for doing that,ubuntu comes with gcc 4.x so install gcc 3.4

sudo apt-get install gcc-3.4 g++-3.4

export CC=gcc-3.4

Download qemu 0.9.0 source , then compile & install


wget http://tx-us.lunar-linux.org/lunar/cache/qemu-0.9.0.tar.gz

tar xzf qemu-0.9.0.tar.gz

cd qemu-0.9.0

./configure
make
make install

I got an error while comiling qemu

Looking for gcc 3.x ./configure: 372: Syntax error: Bad fd number

To fix this edit the ./configure file and change the first line from "#!/bin/sh" to "#!/bin/bash".


Now i was able to install windows 2003 64

qemu-system-x86_64 -m 256 -boot d -cdrom win2003.iso -hda win2003.img -localtime


Installing KQEMU Acceleration Layer

I tried but was not able to get it work

I tried both apt-get kqemu and compiled qemu 0.9.0 and kqemu-1.3 from source,

1st i tried to install with kqemu it got stuck while "starting windows"

Next i tried with -no-kqemu option now 2003 64 installed successfully
After installation i tried with acceleration, initial loading screen came after it screen gone blank.

I installed using

wget http://www.nongnu.org/qemu/kqemu-1.3.0pre11.tar.gz

tar xzf kqemu-1.3.0pre11.tar.gz
cd kqemu-1.3

./configure
make
make install

modprobe kqemu




Installation Experience



Windows 2003 32 bit got stuck while "installing devices" , after restarting it worked fine.

Windows 2003 64 bit installed with not problem

It took 4-5 hours to complete the installation !!!!

Really need great patient to do.. Some steps will take long time with not progress moving.. But may not be stuck.. need waiting...


Windows Experience



Its usable but really slow.. I ran some asp.net sites on that including my home page, its a little bit slow.. but not so bad.
To install .net framework 3.5 it took 1hr!!
Wednesday,08 April,2009 6:00 PM
I saw sumesh for the second time this monday ( i think after 2 years) . We are often in contact(phone,chat) with each other with programming related for the past 4-5 years.. He is the only programmer i know in Alappuzha, We both started with electronics, programming we both came from a VB6 background , We both are self taught programmers with good experience in Programming/System administration.

Tuesday,24 March,2009 5:13 PM
I have created my first orkut application. An english - Malayalam Dictionary. Same as one in my home page.
http://www.orkut.co.in/Main#AppInfo.aspx?appId=160907011366
Thursday,12 March,2009 9:32 AM
ASP.NET MVC Book written by Scott gu,Scott Hanselman, Rob Conery, and Phil Haack

http://www.amazon.com/gp/product/0470384611?ie=UTF8&tag=scoblo04-20&linkCode=xm2&camp=1789&creativeASIN=0470384611

First chaptter of this book is available as a Free Download. 185 pages of walk-through that takes us into creating a complete MVC application (Called Nerddinner) from scratch. Check the application live at http://www.nerddinner.com/. Source code available at codeplex http://nerddinner.codeplex.com/

Download the e-book and source code from scott gu's blog.
http://weblogs.asp.net/scottgu/archive/2009/03/10/free-asp-net-mvc-ebook-tutorial.aspx

Also check scott hanselman's blog about it.
http://www.hanselman.com/blog/FreeASPNETMVCEBookNerdDinnercomWalkthrough.aspx
Tuesday,03 March,2009 3:05 PM
I have a table 'Tags' , see below


To get the rows as XMl

SELECT * FROM Tags for xml auto

The result will be

I want to get the tags separated by coma for the given music id, i wrote a function that
will traverse the XML and return the tags as a single row separated by coma

CREATE FUNCTION [dbo].GetMusicTags
(
@MusicID INT
)
RETURNS VARCHAR(MAX)
AS
BEGIN
DECLARE @Xdoc XML
DECLARE @Count INT
DECLARE @i INT
DECLARE @Tag VARCHAR(MAX)
DECLARE @Temp VARCHAR(MAX)
--
SET @i=1
SET @Tag=''
SET @Temp=''
--
SET @Xdoc=''+(SELECT * FROM Tags WHERE MusicID=@MusicID for xml auto)+''
SET @Count = @Xdoc.query('
{ count(/doc/Tags) }
').value('e[1]','VARCHAR(MAX)')

WHILE @i <= @Count
BEGIN
SELECT @Temp= e.x.value('@Tag[1]', 'VARCHAR(MAX)') FROM
@Xdoc.nodes('/doc/Tags[position()=sql:variable("@i")]') e(x)
SET @Tag=@Tag+@Temp
IF @i<>@Count
SET @Tag=@Tag+','
SET @i = @i + 1
END
RETURN @Tag
END
GO

Result will be


Download Sql Script
Thursday,19 February,2009 12:50 PM


DayOfWeek day = DateTime.Now.DayOfWeek;
int days = day - DayOfWeek.Monday;
DateTime start = DateTime.Now.AddDays(-days);
DateTime end = start.AddDays(6);
Code from
http://www.codekeep.net/snippets/0d955fdd-ff9e-4403-90cb-15dac8391034.aspx
Monday,16 February,2009 6:02 PM
We sometimes stores Coma or other delimiter separated values in a column, to search a particular value in that column, the following function will be helpful.



--30-jan-2009 Priyan R
CREATE FUNCTION [dbo].[IsExistInString]
(
@Data VARCHAR(MAX),
@Delim VARCHAR(100),
@ValueToFind VARCHAR(MAX)
)
RETURNS BIT
AS
BEGIN
DECLARE @pos1 INT
DECLARE @pos2 INT
DECLARE @tbl_Split_Data TABLE
(
Data VARCHAR(MAX)
)
SET @pos1=1
IF(CHARINDEX(@Delim,@Data,1)=0)
BEGIN
INSERT INTO @tbl_Split_Data VALUES(@Data)
END
ELSE
BEGIN
WHILE (@pos1<>0)
BEGIN
SET @pos2=CHARINDEX(@Delim,@Data,@pos1)
IF(@pos2=0)
BEGIN
INSERT INTO @tbl_Split_Data VALUES(SUBSTRING (@Data,@pos1,LEN(@Data)))
END
ELSE
BEGIN
INSERT INTO @tbl_Split_Data VALUES(SUBSTRING (@Data,@Pos1,@Pos2-@Pos1))
END
IF(@pos2<>0) SET @pos2=@pos2+LEN(@Delim)
SET @pos1=@pos2
END
END
SELECT @POS1=COUNT(*) FROM @tbl_Split_Data WHERE Data=@ValueToFind
IF(@POS1<>0)
BEGIN
RETURN 1
END
RETURN 0
END

go
--eg
SELECT dbo.IsExistInString('one|$|two|$|three','|$|','one')
Monday,16 February,2009 4:23 PM
This functions return a string like 1 hours ago, a day ago etc.

//Returns seconds to 1 hour ago, 10 sec ago etc.
public static string SecondsToString(double seconds)
{

string time = "";
if (seconds >= 3600)
{
time =Convert.ToInt32((seconds / 3600)).ToString();
if (seconds > 24)
{
time = Convert.ToInt32((seconds / 24)).ToString();
time += " days ago";
}
else
time += " hrs ago";
}
else if (seconds >= 60)
{
time = Convert.ToInt32((seconds / 60)).ToString();
time += " minutes ago";
}
else
{
time = Convert.ToInt32(seconds).ToString();
time += " sec ago";
}
return time;
}
Wednesday,04 February,2009 3:34 PM
I have been coding in various languages for more than 6 years. Till now i havent used much mathematics for programming. From my experience i feel that one can be a very good programmer without a deep knowledge in maths. But i think proficieny in mathematics will be an added advantage for Programmer. With maths we can write many interesting & funny programs easily without any difficulty.

There is good blog post about it by Steve Yegge.

http://steve-yegge.blogspot.com/2006/03/math-for-programmers.html
First Previous 1 2 Next Last 
Follow Me , Priyan R On Twitter
I Love Code
NSS karuvatt