Infolink

 

Search This Blog

Showing posts with label Asp.Net Basic. Show all posts
Showing posts with label Asp.Net Basic. Show all posts

Oct 19, 2012

ASP.NET Trace

Trace.Write helps diagnose problems in ASP.NET. It determines what is actually running in an ASP.NET application. We review the basics of tracing in ASP.NET. We use the C# language to easily benchmark sites.

First we must add the trace markup to our Web.config file. The sample values in the markup I show can and should be changed by you. I encourage you to flip the attribute values and see what they do as much as possible. Here's how to add the markup.

Open Web.config file. Your ASP.NET project should have a Web.config file. If it doesn't, add one through the Website > Add New Item.... menu. This is an XML file used by ASP.NET to store website configuration settings.

Oct 18, 2012

Generics classes Overview in C#.Net

Generics main benefit is eliminating boxing and unboxing that is true, there are also other benefits like type safety, by using generics you eliminate type ambiguitiy.

  1. Generics provide type safety without the overhead of multiple implementations. Ex. We can create a linked list of string. LinkedListlinkList=new LinkedList(); There is no need to inherit from a base type and override members.The linked list is ready for immediate use.
  2. There is no need to write code to test for the correct data type because it is enforced at compile time. The need for type casting and the possibility of run-time errors are reduced.
  3. Generic collection types generally perform better for storing and manipulating value types because there is no need to box the value types
  4. Generic delegates enable type-safe callbacks without the need to create multiple delegate classes.  

Oct 16, 2012

ASHX handler in Asp.Net

An ASHX handler allows you a discrete http handler without the overhead of processing a page request (an ASPX file).

<%@ WebHandler Language="C#" Class="Handler" %>

using System;
using System.Web;

public class Handler : IHttpHandler {
   
    public void ProcessRequest (HttpContext context) {
        var fileName = "must.sql";
        var r = context.Response;
        r.AddHeader("Content-Disposition", "attachment; filename=" + fileName);
        r.ContentType = "text/plain";
        r.WriteFile(context.Server.MapPath(fileName));

    }
 
    public bool IsReusable {
        get {
            return false;
        }
    }

}
 Now, You have to create button in your .aspx page write the code as following

<asp:Button ID="Button1" runat="server" onclick="Button1_Click" Text="Button" />

protected void Button1_Click(object sender, EventArgs e)
    {
        Response.Redirect("Handler.ashx");
    }
 

Oct 15, 2012

RAISERROR statement in SQL server

RAISERROR statement is used to return error messages to the business applications that executes SQL statements. The usual errors returned by the SQL server may not make much sense to the business applications users hence we overwrite it by using RAISERROR to display meaningful messages. The statement uses same format as a system error or warning messages generated by SQL server.

You can return a user-defined error message by using RAISERROR.  The general syntax is as below

Oct 14, 2012

User Control Example

In this example I show that how easily we can create User Control and then use it in asp.net. Here first I create a User Control name CalendarUserControl.ascx, then place it Default.aspx web form. Here is the source code of both files.

Oct 10, 2012

View State Rendering

The problem in earlier versions is that the viewstate is rendered at the bottom of the page.
If the page is posted back before the entire page is loaded, the viewstate that is being submitted back to the server is incomplete and thus invalid.

This was fixed with .NET 3.5 SP1.

But You can Fix it by below Render function in earlier version of .NET

Oct 3, 2012

The major difference between convert.ToString() and ToString() is that,

convert.ToString() handles null but ToString() does not handles null.

Please see below two set of code:

This code will run successfully, no exception will be raised for that:

    string name = null;

    string abc = Convert.ToString(name);

Below code will give an exception, unhandled Exception:NullReferenceException

    string name = null;

    string abc = name.ToString();
Related Posts Plugin for WordPress, Blogger...