Saturday, December 18, 2010

CalendarExtender and getting the correct date format or change UI Culture of CalenderExtender

Change  ui culture of calendarextender or apply UI Culture on CalenderExtender of Ajax Control toolkit.

 Firstly, add Culture and UI Culture information to your web.config file.

<system.web>
    <globalization uiCulture="en" culture="en-GB" />
system.web>
 
Sett the EnableScriptGlobalization and EnableScriptLocalization to true as properties of the ScriptManager.

<cc1:ToolkitScriptManager ID="ToolkitScriptManager1" runat="server"
    EnablePartialRendering="true"
    EnableScriptGlobalization="true"
    EnableScriptLocalization="true">
cc1:ToolkitScriptManager>

Friday, November 19, 2010

asp.net css on gridview paging

In RowDatabound Event

if (e.Row.RowType == DataControlRowType.Pager)
        {
            TableRow tRow = e.Row.Controls[0].Controls[0].

            Controls[0] as TableRow;


            foreach (TableCell tCell in tRow.Cells)
            {


                Control ctrl = tCell.Controls[0];

                tCell.Attributes.Add("align", "center");
                if (ctrl is LinkButton)
                {


                    LinkButton lb = (LinkButton)ctrl;


                    lb.Width = Unit.Pixel(20);

                    //lb.Attributes.Add("");

                    lb.BackColor = System.Drawing.Color.DarkGray;


                    lb.ForeColor = System.Drawing.Color.White;


                    lb.Attributes.Add("onmouseover",


                       "this.style.backgroundColor='#4f6b72';");


                    lb.Attributes.Add("onmouseout",


                      "this.style.backgroundColor='darkgray';");


                }


            }



        }

Friday, September 3, 2010

Difference between int32,tryparse and convert.toint32


Int32.parse(string)
-------------------------
Int32.Parse (string s) method converts the string representation of a number to its 32-bit signed integer equivalent.
When s is null reference, it will throw ArgumentNullException.
If s is other than integer value, it will throw FormatException.
When s represents a number less than MinValue or greater than MaxValue, it will throw OverflowException.

Example:
------------------
string s1 = "1234";
string s2 = "1234.65";
string s3 = null;
string s4 = "123456789123456789123456789123456789123456789";

int result;
bool success;

result = Int32.Parse(s1); //-- 1234
result = Int32.Parse(s2); //-- FormatException
result = Int32.Parse(s3); //-- ArgumentNullException
result = Int32.Parse(s4); //-- OverflowException


Convert.ToInt32(string)
----------------------------------
Convert.ToInt32(string s) method converts the specified the string representation of 32-bit signed integer equivalent. This calls in turn Int32.Parse () method.
When s is null reference, it will return 0 rather than throw ArgumentNullException
If s is other than integer value, it will throw FormatException.
When s represents a number less than MinValue or greater than MaxValue, it will throw OverflowException

Example:
result = Convert.ToInt32(s1); //-- 1234
result = Convert.ToInt32(s2); //-- FormatException
result = Convert.ToInt32(s3); //-- 0
result = Convert.ToInt32(s4); //-- OverflowException


Int32.TryParse(string, out int)
---------------------------------------------
Int32.Parse(string, out int) method converts the specified the string representation of 32-bit signed integer equivalent to out variable, and returns true if it parsed successfully, false otherwise. This method is available in C# 2.0
When s is null reference, it will return 0 rather than throw ArgumentNullException.
If s is other than integer value, the out variable will have 0 rather than FormatException.
When s represents a number less than MinValue or greater than MaxValue, the out variable will have 0 rather than OverflowException.

Example:-
-------------
success = Int32.TryParse(s1, out result); //-- success => true; result => 1234
success = Int32.TryParse(s2, out result); //-- success => false; result => 0
success = Int32.TryParse(s3, out result); //-- success => false; result => 0
success = Int32.TryParse(s4, out result); //-- success => false; result => 0

Convert.ToInt32 is better than Int32.Parse, since it return 0 rather than exception. But, again according to the requirement this can be used. TryParse will be best since it handles exception itself always.

Monday, July 12, 2010

New features in Asp.Net 4.0

http://www.asp.net/learn/whitepapers/aspnet4 : New features in Asp.Net 4.0

Friday, February 12, 2010

improve performance

http://tweetmeme.com/story/132774594/20-tips-to-improve-aspnet-application-performance-software-development-in-the-real-world
  1. Disable Session State
    Disable Session State if you’re not going to use it.  By default it’s on. You can actually turn this off for specific pages, instead of for every page:

    <%@ Page language="c#" Codebehind="WebForm1.aspx.cs"
    AutoEventWireup="false" Inherits="WebApplication1.WebForm1"
    EnableSessionState="false" %>
    You can also disable it across the application in the web.config by setting the mode value to Off.
  2. Output BufferingTake advantage of this great feature.  Basically batch all of your work on the server, and then run a Response.Flush method to output the data.  This avoids chatty back and forth with the server.

    <%response.buffer=true%> 
    Then use:


    <%response.flush=true%> 
  3. Avoid Server-Side Validation
    Try to avoid server-side validation, use client-side instead. Server-Side will just consume valuable resources on your servers, and cause more chat back and forth.
  4. Repeater Control Good,  DataList, DataGrid, and DataView controls BadAsp.net is a great platform, unfortunately a lot of the controls that were developed are heavy in html, and create not the greatest scaleable html from a performance standpoint.  ASP.net  repeater control is awesome!  Use it!  You might write more code, but you will thank me in the long run!
  5. Take advantage of HttpResponse.IsClientConnected before performing a large operation:

    if (Response.IsClientConnected)
    {
    // If still connected, redirect
    // to another page. 
    Response.Redirect("Page2CS.aspx", false);
    }
    What is wrong with Response.Redirect? Read on…
  6. Use HTTPServerUtility.Transfer instead of Response.RedirectRedirect’s are also very chatty.  They should only be used when you are transferring people to another physical web server.  For any transfers within your server, use .transfer!  You will save a lot of needless HTTP requests.

    When to use httpserverutility.transfer :
    http://kbalertz.com/316920/State-Error-Message.aspx
     
  7. Always check Page.IsValid when using Validator ControlsSo you’ve dropped on some validator controls, and you think your good to go because ASP.net does everything for you!  Right? Wrong!  All that happens if bad data is received is the IsValid flag is set to false. So make sure you check Page.IsValid before processing your forms!
  8. Deploy with Release BuildMake sure you use Release Build mode and not Debug Build when you deploy your site to production. If you think this doesn’t matter, think again.  By running in debug mode, you are creating PDB’s and cranking up the timeout.  Deploy Release mode and you will see the speed improvements.
  9. Turn off Tracing
    Tracing is awesome, however have you remembered to turn it off? If not, make sure you edit your web.config and turn it off!  It will add a lot of overhead to your application that is not needed in a production environment.

    
    
    "false" pageOutput="false" />
    "false" requestLimit="10" pageOutput="false" traceMode="SortByTime" localOnly="true"/>
    "false" />
  10. Page.IsPostBack is your friendMake sure you don’t execute code needlessly. I don’t know how many web developers forget about checking IsPostBack!  It seems like such a basic thing to me!  Needless processing!
  11. Avoid ExceptionsAvoid throwing exceptions, and handling useless exceptions. Exceptions are probably one of the heaviest resource hogs and causes of slowdowns you will ever see in web applications, as well as windows applications.  Write your code so they don’t happen!  Don’t code by exception!
  12. Caching is Possibly the number one tip!Use Quick Page Caching and the ASP.net Cache API!  Lots to learn, its not as simple as you might think.  There is a lot of strategy involved here.  When do you cache?  what do you cache?
  13. Create Per-Request CacheUse HTTPContect.Items to add single page load to create a per-request cache.
  14. StringBuilder
    StringBuilder.Append is faster than String + String.  However in order to use StringBuilder, you must

    new StringBuilder()
    Therefore it is not something you want to use if you don’t have large strings.  If you are concatenating less than 3 times, then stick with String + String. You can also try String.Concat
  15. Turn Off ViewState
    If you are not using form postback, turn off viewsate, by default, controls will turn on viewsate and slow your site.

    public ShowOrdersTablePage()
    {
    this.Init += new EventHandler(Page_Init);
    }
    
    private void Page_Init(object sender, System.EventArgs e)
    {
    this.EnableViewState = false;
    }
  16. Use PagingTake advantage of paging’s simplicity in .net. Only show small subsets of data at a time, allowing the page to load faster.  Just be careful when you mix in caching.  How many times do you hit the page 2, or page 3 button?  Hardly ever right!  So don’t cache all the data in the grid! Think of it this way: How big would the first search result page be for “music” on Google if they cached all the pages from 1 to goggle ;)
  17. Use the AppOffline.htm when updating binariesI hate the generic asp.net error messages!  If I never had to see them again I would be so happy.  Make sure your users never see them!  Use the AppOffline.htm file!
  18. Use ControlState and not ViewState for Controls
    If you followed the last tip, you are probably freaking out at the though of your controls not working.  Simply use Control State.  Microsoft has an excellent example of using ControlState here, as I will not be able to get into all the detail in this short article.
  19. Use the Finally MethodIf you have opened any connections to the database, or files, etc, make sure that you close them at the end!  The Finally block is really the best place to do so, as it is the only block of code that will surely execute.
  20. Option Strict and Option ExplicitThis is an oldy, and not so much a strictly ASP.net tip, but a .net tip in general.  Make sure you turn BOTH on.  you should never trust .net or any compiler to perform conversions for you.  That’s just shady programming, and low quality code anyway.  If you have never turned both on, go turn them on right now and try and compile.  Fix all your errors.
There are hundreds more where these came from, however I really feel that these are the most critical of the speed improvements you can make in ASP.net that will have a dramatic impact on the user experience of your application.  As always if you have any suggestions or tips to add, please let us know!  We would love to hear them!
Have web development!