welcome Netizen

Share Your Knowledge.It is a way to achieve immortality

Saturday, March 23, 2013

Ajax control Toolkit AutoCompleteExtender working with webservice

Here I would like to share ajax control autocomplete extender.By using with this control you can easily attached to any textbox to display suggestion list to the user.
You can get the suggestion list from the database or from XML file to display..
Here is the code to link textbox with AutoCompleteExtender
<asp:UpdatePanel ID="UpdatePanel1" runat="server">
            <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
            <asp:AutoCompleteExtender ID="AutoCompleteExtender1" runat="server" TargetControlID="TextBox1"
                ServiceMethod="GetCompletionList" EnableCaching="true" ServicePath="~/Retrunlist.asmx"
                UseContextKey="True" MinimumPrefixLength="1" CompletionInterval="100" CompletionSetCount="10">

·  TargetControlID - The TextBox control where the user types content to be automatically completed
·  ServiceMethod - The web service method to be called. The signature of this method must match the following:
public string[] GetCompletionList(string prefixText, int count) { ... }
Note that you can replace "GetCompletionList" with a name of your choice, but the return type and parameter name and type must exactly match, including case.
·  ServicePath - The path to the web service that the extender will pull the word\sentence completions from. If this is not provided, the service method should be a page method.
·  ContextKey - User/page specific context provided to an optional overload of the web method described by ServiceMethod/ServicePath. If the context key is used, it should have the same signature with an additional parameter named contextKey of type string:
public string[] GetCompletionList(
    string prefixText, int count, string contextKey) { ... }
Note that you can replace "GetCompletionList" with a name of your choice, but the return type and parameter name and type must exactly match, including case.
·  UseContextKey - Whether or not the ContextKey property should be used. This will be automatically enabled if the ContextKey property is ever set (on either the client or the server). If the context key is used, it should have the same signature with an additional parameter named contextKey of type string (as described above).
·  MinimumPrefixLength - Minimum number of characters that must be entered before getting suggestions from the web service.
·  CompletionInterval - Time in milliseconds when the timer will kick in to get suggestions using the web service.
·  EnableCaching - Whether client side caching is enabled.
·  CompletionSetCount - Number of suggestions to be retrieved from the web service.
·  CompletionListCssClass - Css Class that will be used to style the completion list flyout.
·  CompletionListItemCssClass - Css Class that will be used to style an item in the AutoComplete list flyout.
·  CompletionListHighlightedItemCssClass - Css Class that will be used to style a highlighted item in the AutoComplete list flyout.
·  DelimiterCharacters - Specifies one or more character(s) used to separate words. The text in the AutoComplete textbox is tokenized using these characters and the webservice completes the last token.
·  FirstRowSelected - Determines if the first option in the AutoComplete list will be selected by default.
·  ShowOnlyCurrentWordInCompletionListItem - If true and DelimiterCharacters are specified, then the AutoComplete list items display suggestions for the current word to be completed and do not display the rest of the tokens.
Webservice code:

    public string[] GetCompletionList(string prefixText, int count, string contextKey)
        List<string> collections = new List<string>();

        DataSet ds = new DataSet();


        if (ds.Tables[0].Rows.Count > 0)
            for (int i = 0; i < ds.Tables[0].Rows.Count; i++)
                DataRow dr = ds.Tables[0].Rows[i];

                if (dr[0].ToString().StartsWith(prefixText, StringComparison.InvariantCultureIgnoreCase))

                    if (collections.Count == count) break;


          return collections.ToArray();

XML File structure:
<?xml version="1.0" encoding="utf-8" ?>
  <name>United Kingdom</name>

Now you can run above code autocomplete extender give the suggestion list by entering text on the textbox.
Here you can Download the complete code for the Project

Sunday, March 17, 2013

Interview Questions in ASP.Net PART 1

1. Which method has been introduced in 4.0 to redirect page permanently?

The Redirectpermanent() method added in 4.0  to redirect a page permanently. It’s the method of Page.HTTPReposne class that permanently redirects a requested URL to specified URL and issue HTTP 301response code Moved permanently responses.
Response. RedirectPermanent("/newlocation/oldcontent.aspx");

2. What is the difference between the Response.Write() and Response.Output.write()

The Response.write method allows you to write the normal output
The Response.Output.write() method allows you to write the formatted output.

3. What is the default time out of Cookie?

The default timeout duration of cookie is 30 minutes.

4. What are the event handlers that can be included in the Global.asax file?

Global.asax file contains some of the following important event handlers..

5.What is the appsettings section in the web.config file?

The web.config file sets theconfiguration for a web project.The appsettings block in configuration file sets the user defined values for the whole application. 

6. Where is the viewstate information stored?

Viewstate information stored in HTML hidden fields in client side

7.To which class a web form belongs to in the  .Net frame work class hierarchy?

Web form belongs to the System.web.UI.Page

8.Which event determines all the control are completely loaded in to memory?

The Page_Load event determines that all the control on the page are fully loaded. However you can also access the control in Page_init event but viewstate property does not load completely during this event.

9.What is the function of Viewstate property?

The ASP.Net 4.0 introduced viewstate property.Now you can enable view state to an individual control even the viewstate of the page is diabled.

10.Which two new properties introduced in Asp.Net 4.0 in page class?

Metakeyword and Metadescription.

Multiple file upload in

Here I would like to share a code to upload multiple files using framework 4.0.In a previous I had post article related to multiple file upload control. For your reference below I have mention the link..
In latest framework file upload control has a default properties to upload multiple, just we need to enable the properties
Drag the file upload control and one button
Write the below code on the button event to upload multiple files on the server
           <asp:FileUpload ID="FileUpload2" runat="server"  />
        <asp:FileUpload ID="FileUpload1" runat="server"  multiple="multiple" />
        <br />
        <asp:Button ID="btnUpload" runat="server" Text="Upload All"
            onclick="btnUpload_Click" />

Server code:
protected void btnUpload_Click(object sender, EventArgs e)
            // Get the HttpFileCollection
            HttpFileCollection Filecll = Request.Files;
            for (int i = 0; i < Filecll.Count; i++)
                HttpPostedFile hpf = Filecll[i];
                if (hpf.ContentLength > 0)
                    hpf.SaveAs(Server.MapPath("Images") + "\\" + System.IO.Path.GetFileName(hpf.FileName));
                    Response.Write("<b>File: </b>" + hpf.FileName + " <b>Size:</b> " +
                        hpf.ContentLength + " <b>Type:</b> " + hpf.ContentType + " Uploaded Successfully <br/>");
        catch (Exception ex)


Selected file has been moved to server images folder.
Note: when doing selection you need to select multiple file or single file to upload…
Click here to Download project file
Post your comments………