Thursday, November 1, 2012

string was not recognized as a valid datetime in Asp.Net

DateTime.ParseExact which parses a date that exactly matches a format you supply.



string date1 = "12/29/2011";
        DateTime date2 = DateTime.ParseExact(date1, "MM/dd/yyyy", null);

null means the current culture.
 OR

using System.Globalization;


date2 = DateTime.ParseExact(date1, "MM/dd/yyyy HH:mm:ss", CultureInfo.InvariantCulture);





Saturday, October 20, 2012

Email Binding in Asp.Net GridView




<asp:TemplateField HeaderText="Email">
                        <ItemTemplate>
                            <asp:HyperLink runat="server" ID="HyperLink1" NavigateUrl='<%# string.Format("mailto:{0}", Eval("Email")) %>'
                                Text='<%# Eval("Email") %>' />
                        </ItemTemplate>
                        
                    </asp:TemplateField>


Tuesday, October 2, 2012

Maxlength of Multilne Textbox in ASP.Net


<script language="javascript" type="text/javascript">
function textboxMultilineMaxNumber(txt, maxLen)
{
    try {
        if ((txt.value.length) > (maxLen-1 ))
        return false;
        }
 catch (e)
    {
    }
}
    </script>




<asp:TextBox ID="TextBox1" runat="server" Width="200px" TextMode="MultiLine" Height="100px"  onkeypress="return textboxMultilineMaxNumber(this,5)"></asp:TextBox>

Disable Cut, Copy & Paste in ASP.Net textbox

  <asp:TextBox ID="TextBox1" runat="server" oncopy="return false" onpaste="return false"
            oncut="return false"></asp:TextBox>

Monday, March 19, 2012

Generate random file names in Asp.net


//Random FileName with Random Extension
        string fileName = System.IO.Path.GetRandomFileName();

        //Random FileName without Random Extension
        string fileNameWithoutExtension = System.IO.Path.GetFileNameWithoutExtension(System.IO.Path.GetRandomFileName());

Thursday, January 5, 2012

Browser Detection in ASP.NET

System.Web.HttpBrowserCapabilities browser = Request.Browser;
                    string name = browser.Browser;
                    float version = (float)(browser.MajorVersion + browser.MinorVersion);
                    if ((name == "IE" && version == 6))
                    {
                     
                    }
                 

Ajax CalendarExtender displaying at wrong position in Chrome

< script type ="text/javascript" language ="javascript">     function onCalendarShown(sender, args)...