"If at first you don't succeed; call it version 1.0" :-Unknown

Pages

Saturday, May 15, 2010

AutoNumber Column or Auto Number in GridView or DataList ASP.NET

 Hi,
I posted early adding Serial Number on datagrid and that was through itemdatabound sometimes it may cause ur pjt to run a bit slow.on client-side Serial Number a nice concept is it...

Here v Go...


<asp:GridView ID="GridView1" runat="server"
              AllowPaging="True" AutoGenerateColumns="False">
    <Columns>
    <asp:TemplateField HeaderText="Serial Number">
    <ItemTemplate>
        <%# Container.DataItemIndex + 1 %>
    </ItemTemplate>
    </asp:TemplateField>
    <asp:BoundField DataField="Name" HeaderText="Name"/>
    </Columns>
    </asp:GridView>


I hope this will help u....
Have a nice day... 'N happy Coding :)

ASP.NET Data Web Controls Kick StartProfessional DevExpress ASP.NET Controls (Wrox Programmer to Programmer)

Detecting Session Timeout and Redirect to Login Page in ASP.NET

Hi ,
V can do this by calling the Page_Init() function.. I hope everybody have an idea abt this function.v are checking our session value on this function.

Code

    protected void Page_Load(object sender, EventArgs e)
    {

    }
    protected void Page_Init(object sender, EventArgs e)
    {
        CheckSession();
    }
    private void CheckSession()
    {
        if (Session["SessionID"] == null)
        {
            Response.Redirect("Login.aspx"); // This means session haves no value
        }
    }
I hope this will help you

Have a nice day... 'N happy Coding :)

This Is UsMillenniumThe Hits--Chapter One 

Friday, May 14, 2010

To check given String is Url or not using Regular Expression

Hi everyboday,
Few days back my friend ask me abt validating a  string that it contain a url or not.
Visual stdio is giving us a in-build option to check this so what v need is to cal this control on server side and validate it Simple :) 

To call Regular Expression on server side v need to add a name space
using System.Text.RegularExpressions;


validate URL's without http
 
Private bool ValidateUrl(string url)
{
// regex pattern for url validation string
Regex RgxUrl = new Regex("(([a-zA-Z][0-9a-zA-Z+\\-\\.]*:)?/{0,2}[0-9a-zA-Z;/?:@&=+$\\.\\-_!~*'()%]+)?(#[0-9a-zA-Z;/?:@&=+$\\.\\-_!~*'()%]+)?");
if (RgxUrl.IsMatch(url))
{
return true;// string url contain valid url
}
else
{
return false;
// string url contain invalid url
}

}


validate URL's with http



 

Private bool ValidateUrl(string url)
{
System.Globalization.CompareInfo cmpUrl = System.Globalization.CultureInfo.InvariantCulture.CompareInfo;
if(cmpUrl.IsPrefix(txtUrl.Text, "http://") == false)
{
txtUrl.Text = "http://" + txtUrl.Text;
}
Regex RgxUrl = new Regex("(([a-zA-Z][0-9a-zA-Z+\\-\\.]*:)?/{0,2}[0-9a-zA-Z;/?:@&=+$\\.\\-_!~*'()%]+)?(#[0-9a-zA-Z;/?:@&=+$\\.\\-_!~*'()%]+)?");
if (RgxUrl.IsMatch(url))
{
return true;
}
else
{
return false;
}
}

Have a nice day... 'N happy Coding :)
 Hackers: Heroes of the Computer RevolutionHackersThe Web Application Hacker's Handbook: Discovering and Exploiting Security Flaws