vijay

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">
        <ContentTemplate>
            <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">
            </asp:AutoCompleteExtender>
        </ContentTemplate>
    </asp:UpdatePanel>


Properties
·  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:
[System.Web.Services.WebMethod]
[System.Web.Script.Services.ScriptMethod]
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:
[System.Web.Services.WebMethod]
[System.Web.Script.Services.ScriptMethod]
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:
[WebMethod]

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

        DataSet ds = new DataSet();

        ds.ReadXml(HttpContext.Current.Server.MapPath("sample.xml"));

        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))
                {
                    collections.Add(dr[0].ToString());

                    if (collections.Count == count) break;
                }

            }

        }
          return collections.ToArray();
            }


XML File structure:
Sample.xml
<?xml version="1.0" encoding="utf-8" ?>
<country>
  <name>India</name>
  <name>Iran</name>
  <name>America</name>
  <name>Afhanistan</name>
  <name>Russia</name>
  <name>Pakistan</name>
  <name>United Kingdom</name>
  <name>Dubai</name> 
</country>

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 asp.net 4.0 to redirect page permanently?

The Redirectpermanent() method added in Asp.net 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..
*Application_error
*Application_start
*Application_End
*Session_Start
*Session_End

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 asp.net



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
Steps:
Drag the file upload control and one button
Write the below code on the button event to upload multiple files on the server
<div>
           <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" />
    </div>

Server code:
protected void btnUpload_Click(object sender, EventArgs e)
    {
        try
        {
            // 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………