Infolink

 

Search This Blog

Showing posts with label ASP.NET Applications in MVC. Show all posts
Showing posts with label ASP.NET Applications in MVC. Show all posts

Oct 19, 2012

Tooltip User Control

I have created Tooltip control that replaces standard browsers' tooltips with custom ones. You can write your own html template to customize it's look and feel.

The control derives on the client from Sys.UI.Control, and is implemented as WebControl on the server.

It is really easy to use it and it gives really nice experience.

Here is a source for a very simple page showing how to use it:


Oct 18, 2012

How to use C# HashTable Class

Hashtable in C# represents a collection of key/value pairs which maps keys to value. Any non-null object can be used as a key but a value can. We can retrieve items from hashTable to provide the key . Both keys and values are Objects.

The commonly used functions in Hashtable are :

  Add                   : To add a pair of value in HashTable
  ContainsKey    : Check if a specified key exist or not
  ContainsValue  : Check the specified Value exist in HashTable


Remove : Remove the specified Key and corresponding Value

Add : To add a pair of value in HashTable

Syntax : HashTable.Add(Key,Value)
  Key : The Key value
  Value : The value of corresponding key
  Hashtable ht;

ht.Add("1", "Sunday");

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");
    }
 

Stop default Auto-Complete of ASP.net TextBox on all browser

If you use textBox properties AutoCompleteType="Disabled" it disables the autocompletes of textBox on only Internet explorer. There's another way to stop auto-complete on all browsers. Use autocomplete="off" on from tag instead of AutoCompleteType = "Disabled". Again you can use the TextBox1.Attributes.Add("autocomplete", "off"); to stop auto-complete on only specific TextBox control.

So, my findings are use the following code to stop autocomplete on specific control

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.

Creating a UserControl

we will be building a UserControl for displaying information about a community user.
First of all, let's add a UserControl to our project. In your Visual Studio or Visual Web Developer, you should be able to right click on your project and select Add new item.. A dialog will pop up, and you should select the Web User Control from the list of possible things to add. Let's call our UserControl UserInfoBoxControl, with the filename of UserInfoBoxControl.ascx. Make sure that you have checked the checkbox which places code in a separate file, the so-called CodeBehind file.

You should now have a UserInfoBoxControl.ascx and a UserInfoBoxControl.ascx.cs in your project. The first is where we put our markup, and the second is our CodeBehind file. Now, if UserInfoBoxControl.ascx is not already open and selected, do so now. You will see only one line of code, the UserControl declaration. As mentioned, this control will be displaying information about a user, so let's get started adding some markup to do so:

ASP.net Ajax

ASP.net Ajax is Microsoft's free framework for creating Ajax (Asynchronous Javascript and XML) web applications. At its simplest, it lets ASP developers do this - or add Ajax controls to their existing applications - without leaving their familiar drag-and-drop environment, and without having to understand Javascript or asynchronous communication with the host. According to the O'Reilly Network, it protects developers from "the underlying gibberish that makes it [Ajax] all work".
Related Posts Plugin for WordPress, Blogger...