0% found this document useful (0 votes)
26 views16 pages

AWP Unit 5

The document discusses XML, XML classes like XmlTextWriter, XmlTextReader, XDocument and XElement. It provides examples of using these classes to read, write and manipulate XML documents and data. It also discusses XML validation against a schema to check that an XML file complies with the defined structure and data types.

Uploaded by

Mahesh Kudalkar
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
26 views16 pages

AWP Unit 5

The document discusses XML, XML classes like XmlTextWriter, XmlTextReader, XDocument and XElement. It provides examples of using these classes to read, write and manipulate XML documents and data. It also discusses XML validation against a schema to check that an XML file complies with the defined structure and data types.

Uploaded by

Mahesh Kudalkar
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 16

Unit-V

Topics:
XML| Security Fundamentals |ASP.NET AJAX
Q1. What is XML? List the various XML classes.
Extensible Markup Language (XML) stores and transports data. If we use a XML file to store the data
then we can do operations with the XML file directly without using the database. The XML format is
supported for all applications.
It is independent of all software applications and it is accessible by all applications. It is a very widely
used format for exchanging data, mainly because it's easy readable for both humans and machines. If
we have ever written a website in HTML, XML will look very familiar to us, as it's basically a stricter
version of HTML. XML is made up of tags, attributes and values and looks something like this:
<?xmlversion="1.0"encoding="utf-8"?>
<EmployeeInformation>
<Details>
<Name>Richa</Name>
<Emp_id>1</Emp_id>
<Qualification>MCA</Qualification>
</Details>
</EmployeeInformation>
XML Classes:
ASP.NET provides a rich set of classes for XML manipulation in several namespaces that start with
System.Xml. The classes here allow us to read and write XML files, manipulate XML data in memory,
and even validate XML documents.
The following options for dealing with XML data:
XmlTextWriter
The XmlTextWriter class allows us to write XML to a file. This class contains a number of methods and
properties that will do a lot of the work for us. To use this class, we create a new XmlTextWriter object.
XmlTextReader
Reading the XML document in our code is just as easy with the corresponding XmlTextReader class.
The XmlTextReader moves through our document from top to bottom, one node at a time. We call the
Read() method to move to the next node. This method returns true if there are more nodes to read or
false once it has read the final node.
XDocument
The XDocument class contains the information necessary for a valid XML document. This includes an
XML declaration, processing instructions, and comments. The XDocument makes it easy to read and
navigate XML content. We can use the static XDocument.Load() method to read XML documents from
a file, URI, or stream.
Q2. What is XmlTextWriter? Explain with example
XmlTextWriter is one of many useful classes in System.Xml namespace, and it provides several useful
methods to write a complete XML Document from scratch.
Following form is simple ASP.NET web form asking user to input some data about the product. I will
save this data in a separate XML document named Product.xml using XmlTextWriter object.

93
Following C# code is saving all the user input values in XML file.
protected void Button1_Click(object sender, EventArgs e)
{
XmlTextWriter writer = null;
try
{
string filePath = Server.MapPath("~") + "\\Product.xml";
writer = new XmlTextWriter(filePath, System.Text.Encoding.UTF8);
writer.Formatting = Formatting.Indented;
writer.WriteComment("Created On: " + DateTime.Now.ToString("dd-MMM-yyyy"));
writer.WriteComment("===============================");
writer.WriteStartElement("Product");
writer.WriteAttributeString("ProductID", TextBox1.Text);
writer.WriteElementString("ProductName", TextBox2.Text);
writer.WriteElementString("ProductQuantity", TextBox3.Text);
writer.WriteElementString("ProductPrice", TextBox4.Text);
writer.WriteEndElement();
writer.WriteEndDocument();
writer.Flush();
Response.Redirect("Product.xml");
}
catch (Exception ex){ }
}
Q3. What is XmlTextReader? Explain with example
Reading the XML document in our code is just as easy with the corresponding XmlTextReader class.
The XmlTextReader moves through our document from top to bottom, one node at a time.
Example:
TernTenders.xml
<?xml version="1.0" encoding="utf-8" ?>
<Tenders>
<Ravina>
<BillNo>1</BillNo>
<PageNo>10</PageNo>
<Activity>Metals</Activity>
</Ravina>
<Ravina>
<BillNo>2</BillNo>
<PageNo>20</PageNo>
<Activity>Formworks</Activity>
</Ravina>
< Ravina>
<BillNo>3</BillNo>
<PageNo>30</PageNo>
<Activity>SiteWorks</Activity>
</ Ravina>
</Tenders>
ASPX Page:
<asp:GridView ID="GridView1" runat="server"></asp:GridView>
<asp:DropDownList ID="DropDownList1BillNo" runat="server"></asp:DropDownList>

94
<asp:DropDownList ID="DropDownList2PageNo" runat="server"></asp:DropDownList>
<asp:DropDownList ID="DropDownList3Activity" runat="server"></asp:DropDownList>
Code behind Page
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
BindDataToGridview();
}
}
protected void BindDataToGridview()
{
XmlTextReader xmlreader = new
XmlTextReader(Server.MapPath("~/App_Data/TernTenders.xml"));
DataSet ds = new DataSet();
ds.ReadXml(xmlreader);
xmlreader.Close();
if (ds.Tables.Count != 0)
{
GridView1.DataSource = ds;
GridView1.DataBind();

DropDownList1BillNo.DataSource = ds;
DropDownList1BillNo.DataTextField = "BillNo";
DropDownList1BillNo.DataValueField = "BillNo";
DropDownList1BillNo.DataBind();

DropDownList2PageNo.DataSource = ds;
DropDownList2PageNo.DataTextField = "PageNo";
DropDownList2PageNo.DataValueField = "PageNo";
DropDownList2PageNo.DataBind();

DropDownList3Activity.DataSource = ds;
DropDownList3Activity.DataTextField = "Activity";
DropDownList3Activity.DataValueField = "Activity";
DropDownList3Activity.DataBind();
}
}

Q4. What is XDocument? Explain with example


The XDocument class contains the information necessary for a valid XML document. This includes an
XML declaration, processing instructions, and comments. The XDocument makes it easy to read and
navigate XML content. We can use the static XDocument.Load() method to read XML documents from
a file, URI, or stream.

95
Example:
TernTenders.xml
<?xml version="1.0" encoding="utf-8" ?>
<Tenders>
<Ravina>
<BillNo>1</BillNo>
<PageNo>10</PageNo>
<Activity>Metals</Activity>
</Ravina>
<Ravina>
<BillNo>2</BillNo>
<PageNo>20</PageNo>
<Activity>Formworks</Activity>
</Ravina>
< Ravina>
<BillNo>3</BillNo>
<PageNo>30</PageNo>
<Activity>SiteWorks</Activity>
</ Ravina>
</Tenders>
ASPX Page:
<asp:Button ID="ReadXmlUsingXMLDocument" runat="server"
Text="ReadXMLDataUsingXMLDocument" OnClick="ReadXmlUsingXMLDocument_Click" />
<asp:ListBox ID="ListBox2" runat="server" Height="500px" Width="500px"></asp:ListBox>
Code behind Page
protected void ReadXmlUsingXMLDocument_Click(object sender, EventArgs e)
{
XmlDocument doc = new XmlDocument();
doc.Load(Server.MapPath("~/App_Data/TernTenders.xml"));
XmlNodeList elemList = doc.GetElementsByTagName("Activity");
for (int i = 0; i < elemList.Count; i++)
{
ListBox2.Items.Add(elemList[i].InnerXml);
}
}

Q5. What is XElement? Explain with example


The XElement class represents an XML element in System.Xml.XLinq. XElement loads and parses XML.
It allows us to remove lots of old code and eliminate the possibility of bugs and typos. The XAttribute
class represents an attribute of an element. XElement.Save method saves the contents of XElement to
a XML file.
Example:
Authors.xml

96
<?xml version="1.0" encoding="utf-8" ?>
<Authors>
<Author Name="Mahesh Chand">
<Book>GDI+ Programming</Book>
<Cost>$49.95</Cost>
<Publisher>Addison-Wesley</Publisher>
</Author>
<Author Name="Mike Gold">
<Book>Programmer's Guide to C#</Book>
<Cost>$44.95</Cost>
<Publisher>Microgold Publishing</Publisher>
</Author>
<Author Name="Scott Lysle">
<Book>Custom Controls</Book>
<Cost>$39.95</Cost>
<Publisher>C# Corner</Publisher>
</Author>
</Authors>
Code Behind
XElement allData = XElement.Load(Server.MapPath("~/App_Data/ Authors.xml")
if (allData != null)
{
IEnumerable<XElement> authors = allData.Descendants("Author");
foreach(XElement author in authors)
Response.Write ((string) author);
}
Q6. What is XML Validation?
The validation of an Xml input File could occur at various instances of processing as mentioned below:
 using a schema file
 In the Database Code for validating against business rules.
All Xml code can be considered as categorically correct if they are well-formed and valid xml files.
Well-formed - The XML code must be syntactically correct or the XML parser will raise an error.
Valid - If the XML file has an associated XML Schema, the elements must appear in the defined
structure and the content of the individual elements must conform to the declared data types
specified in the schema.
Validation of Xml Files can be achieved through the use of various Technologies ex. Visual Studio Net.
Also, there are many on-line Tools available for validating an input .xml File. Few of them are
mentioned below:
Xml Schema Validation
An Xml File is generally validated for its conformance to a particular schema. The Xml schema file
usually is a XML Schema definition language (XSD). The input Xml File could be even validated against a
set of Schema Files. The Schema File is the structural representation of how a given Xml Data File
should resemble.
Validation using XSL Technology:
XSLT [Extended Stylesheet Language Transformation] is basically used for transforming the input xml
File from one form to another, which could be .html, .xml etc. Here, we use XSLT to transform the
input Xml File to a form that we require for further processing

97
Q7. What is XML Transform using XslCompiledTransform Class? Explain with example
In the .NET Framework a class XslCompiledTransform is present in the System.Xml.Xsl namespace that
can be used to do the transformation. Then theXslCompiledTransform object calls the Load () method
to load the XSLT file content into the object.
Example:
Data.xml
<?xml version='1.0'?>
<bookstore>
<book genre="A" publicationdate="1981" ISBN="1-11111-11-0">
<title>title 1</title>
<author>
<first-name>A</first-name>
<last-name>B</last-name>
</author>
<price>8</price>
</book>
<book genre="B" publicationdate="1999" ISBN="0-222-22222-2">
<title>title 2</title>
<author>
<first-name>C</first-name>
<last-name>D</last-name>
</author>
<price>11.99</price>
</book>
</bookstore>
Data.xsl
<?xml version="1.0" encoding="utf-8" ?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
<xsl:template match="/">
<xsl:element name="Authors">
<xsl:apply-templates select="//book"/>
</xsl:element>
</xsl:template>
<xsl:template match="book">
<xsl:element name="Author">
<xsl:value-of select="author/first-name"/>
<xsl:text> </xsl:text>
<xsl:value-of select="author/last-name"/>
</xsl:element>
</xsl:template>
</xsl:stylesheet>

protected void Page_Load(object sender, EventArgs e)


{
Response.ContentType = "text/xml";

string xsltFile = Path.Combine(Request.PhysicalApplicationPath, "Data.xslt");


string xmlFile = Path.Combine(Request.PhysicalApplicationPath, "Data.xml");

XslCompiledTransform xslt = new XslCompiledTransform();

98
xslt.Load(xsltFile);

XPathDocument doc = new XPathDocument(xmlFile);


xslt.Transform(doc, new XmlTextWriter(Response.Output));
}
Q8. What do you mean by authentication? Explain its types.
Authentication is process of validating the identity of a user so the user can be granted access to an
application. A user must typically supply a user name and password to be authenticated.
After a user authenticated, the user must still be authorized to use the required application. The
process of granting user access to an application is called authorization.
There are 3 types of authentication as follows:

Windows-based authentication:
 It causes the browser to display a login dialog box when the user attempts to access restricted page.
 It is supported by most browsers.
 It is configured through the IIS management console.
 It uses windows user accounts and directory rights to grant access to restricted pages.

Forms-based authentication:
 Developer codes a login form that gets the user name and password.
 The username and password entered by user are encrypted if the login page uses a secure
connection.
 It doesn’t reply on windows user account.

Windows Live ID authentication:


 It is centralized authentication service offered by Microsoft.
 The advantage is that the user only has one maintain one username and password.
Q9. What do you mean by Impersonation in ASP.NET?
99
ASP.NET impersonation is used to control the execution of the code in authenticated and authorized
client. It is not a default process in the ASP.NET application. It is used for executing the local thread in
an application. If the code changes the thread, the new thread executes the process identity by
default.
The impersonation can be enabled in two ways as mentioned below:
Impersonation enabled: ASP.NET impersonates the token passed to it by IIS, can be an authenticated
user or an internet user account. The syntax for enabling is as shown below:
<identity impersonate=”true” />
Impersonation enabled for a specific identity: ASP.NET impersonates the token generated using the
identity specified in the Web.config file.
<identity impersonate=”true”
userName=”domain\user”
password=”password” />
Impersonation disabled: It is the default setting for the ASP.NET application. The process identity of the
application worker process is the ASP.NET account.
<identity impersonate=”false” />
Q10. Steps to use Windows authentication with sample code
When we configure our ASP.NET application as windows authentication it will use local windows user
and groups to do authentication and authorization for our ASP.NET pages.
In ‘web.config’ file set the authentication mode to ‘Windows’ as shown in the below code snippets.
<authentication mode="Windows"/>
We also need to ensure that all users are denied except authorized users. The below code snippet
inside the authorization tag that all users are denied. ‘?’ indicates any
<authorization>
<deny users="?"/>
</authorization>
We also need to specify the authorization part. We need to insert the below snippet in the
‘web.config’ file .stating that only ‘Administrator’ users will have access to
<location path="Admin.aspx">
<system.web>
<authorization>
<allow roles="questpon-srize2\Administrator"/>
<deny users="*"/>
</authorization>
</system.web>
</location>
The next step is to compile the project and upload the same on an IIS virtual directory. On the IIS
virtual directory we need to ensure to remove anonymous access and check the integrated windows
authentication.
Now if we run the web application we will be popped with a userid and password box.
Q11. Short note on Web Site Administration Tool (WAT) in ASP.NET.
Another way to set up our authentication and authorization rules. Rather than edit the web.config
file by hand, we can use the WAT from inside Visual Studio. It’s also often quicker to enter a list of
authorization rules by hand than to use the WAT.

100
To use the WAT for this type of configuration, select Website ➤ ASP.NET Configuration from the menu.
Next, click the Security tab.
We will see the window shown in figure, which gives us links to set the authentication type, define
authorization rules (using the Access Rules section), and enable role-based security. (Role-based security
is an optional higher-level feature we can use with forms authentication.

To set an application to use forms authentication, follow these steps:


1. Click Select Authentication Type.
2. Choose the From the Internet option.
3. Click Done. The appropriate <authorization> tag will be created in the web.config file.
Next, it’s time to define the authorization rules. To do so, click the Create Access Rules link.

Q12. What is AJAX? Its Advantages and Disadvantages


Asynchronous JavaScript and XML (AJAX) is a development technique used to create interactive web
applications or rich internet applications.

101
AJAX uses several existing technologies together, including: XHTML, CSS, JavaScript, Document Object
Model, XML, XSLT, and the XMLHttpRequest object.
With AJAX, web applications can retrieve data from the server asynchronously, in the background,
without reloading the entire browser page. The use of AJAX has led to an increase in interactive
animation on web pages
Advantages
 Reduces the traffic travels between the client and the server.
 No cross browser pains.
 Better interactivity and responsiveness.
 With AJAX, several multipurpose applications and features can be handled using a single web
page(SPA).
 API's are good because those work with HTTP method and JavaScript.
Disadvantages
 Search engines like Google would not be able to index an AJAX application.
 It is totally built-in JavaScript code. If any user disables JS in the browser, it won't work.
 The server information cannot be accessed within AJAX.
 Security is less in AJAX applications as all the files are downloaded at client side.
 The data of all requests is URL-encoded, which increases the size of the request.
Q13. What are the benefits using Ajax? Explain UpdatePanel and ScriptManager.
The major benefit of Ajax is partial page rendering. The partial update of a page does not necessitate
full reload of the page and hence leads to flicker-free page rendering.
UpdatePanel
 We can refresh the selected part of the web page by using UpdatePanel control, Ajax UpdatePanel
control contains a two child tags that is ContentTemplate and Triggers. In a ContentTemplate tag we
used to place the user controls and the Trigger tag allows us to define certain triggers which will
make the panel update its content.
<asp:UpdatePanel ID="updatepnl" runat="server">
<ContentTemplate>

 All the contents that must be updated asynchronously (only ContentTemplate parts are updated
and rest of the web page part is untouched) are placed here. It allows us to send request or post
data to server without submit the whole page so that is called asynchronous.
 UpdatePanel is a container control. A page can have multiple update panels.
 The UpdatePanel control enables you to create a flicker free page by providing partial-page update
support to it.
 It identifies a set of server controls to be updated using an asynchronous post back.
 If a control within the UpdatePanel causes a post back to the server, only the content within that
UpdatePanel is refreshed.
<asp:UpdatePanel ID="UpdatePanel1" runat="server">
<ContentTemplate>
</ContentTemplate>
</asp:UpdatePanel>
102
ScriptManager
 The ScripManager Control manages the partial page updates for UpdatPanel controls that are on
the ASP.NET web page or inside a user control on the web page.
 This control manages the client script for AJAX-enabled ASP.NET web page and ScripManager
control support the feature as partial-page rendering and web-service calls.
 The ScriptManager control manages client script for AJAX-enabled ASP.NET Web pages.
 Although this control is not visible at runtime, it is one of the most important controls for an Ajax
enabled web page.
 There can be only one ScriptManager in an Ajax enabled web page.

<asp:ScriptManager ID="ScriptManager1" runat="server" />


Q14. Explain the use of UpdateProgress control in AJAX.
The UpdateProgress provides status information about partial page updates in UpdatePanel controls.
Despite the visual problems that post backs usually cause, they have one big advantage: the user can
see something is happening.
The UpdatePanel makes this a little more difficult. Users have no visual cue that something is
happening until it has happened. To tell users to hold on for a few seconds while their request is
being processed, we can use the UpdateProgress control.
We usually put text such as “Please wait” or an animated image in this template to let the user know
something is happening, although any other markup is acceptable as well. We can connect the
UpdateProgress control to an UpdatePanel using the AssociatedUpdatePanelID property.
Its contents, defined in the <ProgressTemplate> element, are then displayed whenever the
associated UpdatePanel is busy refreshing.
Example:
In the example below, we use the same .gif to display progress while the UpdatePanel is updating its
content. For understanding purposes, we have emulated a time-consuming operation by setting a
delay of 3 seconds by using Thread.Sleep(3000) on the button click.
protected void btnInvoke_Click(object sender, EventArgs e)
{
System.Threading.Thread.Sleep(3000);
lblText.Text = "Processing completed";
}
<asp:ScriptManager ID="ScriptManager1" runat="server">
</asp:ScriptManager>
<asp:UpdateProgress ID="updProgress"
AssociatedUpdatePanelID="UpdatePanel1"
runat="server">
<ProgressTemplate>
<img alt="progress" src="images/progress.gif"/>
Processing...
</ProgressTemplate>
</asp:UpdateProgress>

<asp:UpdatePanel ID="UpdatePanel1" runat="server">


<ContentTemplate>
<asp:Label ID="lblText" runat="server" Text=""></asp:Label>
<br />
<asp:Button ID="btnInvoke" runat="server" Text="Click"
onclick="btnInvoke_Click" />

103
</ContentTemplate>
</asp:UpdatePanel>
In the code shown above, we use the AssociatedUpdatePanelID property of the UpdateProgress
control to associate it with an UpdatePanel control. The ProgressTemplate property that can contain
HTML, is used to specify the message displayed by an UpdateProgress control. In our case, we are
displaying a .gif image progress as shown below.

Q15. Explain the use of Timer control in AJAX.


Timer controls allow us to do postbacks at certain intervals. If used together with UpdatePanel, which
is the most common approach, it allows for timed partial updates of our page, but it can be used for
posting back the entire page as well.
The Timer control uses the interval attribute to define the number of milliseconds to occur before
firing the Tick event.

<asp:Timer ID="Timer1" runat="server" Interval="2000" OnTick="Timer1_Tick">


</asp:Timer>
Example:
Here is a small example of using the Timer control. It simply updates a timestamp every 5 seconds.
<asp:ScriptManager ID="ScriptManager1" runat="server" />
<asp:Timer runat="server" id="UpdateTimer" interval="5000" ontick="UpdateTimer_Tick" />
<asp:UpdatePanel runat="server" id="TimedPanel" updatemode="Conditional">
<Triggers>
<asp:AsyncPostBackTrigger controlid="UpdateTimer" eventname="Tick" />
</Triggers>
<ContentTemplate>
<asp:Label runat="server" id="DateStampLabel" />
</ContentTemplate>
</asp:UpdatePanel>
We only have a single CodeBehind function, which we should add to our CodeBehind file:
protected void UpdateTimer_Tick(object sender, EventArgs e)
{
DateStampLabel.Text = DateTime.Now.ToString();
}
Q16. Explain ASP.NET AJAX Control Toolkit.
The Ajax Control Toolkit is an open source library for web development. The ASP.net Ajax Control
toolkit contains highly rich web development controls for creating responsive and interactive AJAX
enabled web applications.

104
ASP.Net Ajax Control Toolkit contains 40 + ready controls which is easy to use for fast productivity.
Controls are available in the Visual Studio Toolbox for easy drag and drop integration with our web
application. Some of the controls are like AutoComplete, Color Picker, Calendar, Watermark, Modal
Popup Extender, Slideshow Extender and more of the useful controls.
The ASP.Net AJAX Control toolkit is now maintained by DevExpress Team. The Current Version of
ASP.Net AJAX Toolkit is v16.1.0.0. There are lot of new enhancement in the current version from new
controls to bug fixes in all controls.
The ASP.NET AJAX Control Toolkit has a lot going for it:
 It’s completely free.
 It includes full source code, which is helpful if we’re ambitious enough to want to create our own
custom controls that use ASP.NET AJAX features.
 It uses extenders that enhance the standard ASP.NET web controls. That way, we don’t have to
replace all the controls on our web pages.

Q17. Explain Accordion in ASP.NET AJAX Control Toolkit.


Accordion control provides us multiple collapsible panes or panels where only one can be
expanded at a time. Each AccordionPane control has a template for its Header and its content.
Accordion Web Control contains multiple panes and shows one at a time. The panes contain
content of images and text having wide range of supported properties from formatting of the
panes and text, like header and content templates, also it formats the selected header template.
Accordion contains multiple collapsible panes while one can be shown at a time and the extended
features of accordion also has support data source which points to the DataSourceID and binds
through .DataBind() method.
Example we have lot of paragraphs in a single page and we don’t have much space and want to
summarize in small space then we need to embed to the div or some container which can hold all
the information in accordion collapsible pans.
1. Go to File, New, then Website and Create an Empty Website. Add a webform (Default.aspx) in it.
2. Add ScriptManager from AJAX Extensions (from v15.1 of AJAX Control Toolkit,
ToolScriptManager is removed. Use Standard Script Manager).

3. Go to AJAX Control Toolkit in Toolbox and drop Accordion Control on Default.aspx.

105
4. Add AccordionPane in Panes collection of the Accordion.

AccordionPane contains two parts i.e. Header and Content. When AccordionPane is collapsed,
only Header part is visible to us.

Accordion control have several other properties like:


 FadeTransitions: FadeTransitions is used for adding the transition effect.
 SelectedIndex: The AccordionPane to be initially visible.
 TransitionDuration: Number of milliseconds to animate the transitions.
 Panes: Collection of AccordionPane controls.

Q18. Explain AutoCompleteExtender in ASP.NET AJAX Control Toolkit.


AutoComplete is an ASP.NET AJAX extender that can be attached to any TextBox control and will
associate that control with a Popup panel to display a result returned from web services or
retrieved from a database on the basis of text in a TextBox.
The Dropdown with name retrieved from the database or web service is positioned on the
bottom-left of the TextBox.
Properties of AutoCompleteExtender:
 TargetControlID: The TextBox control Id where the user types text to be automatically completed.
 EnableCaching: Whether client-side caching is enabled.
 CompletionSetCount: Number of suggestions to be retrieved from the web service.
 MinimumPrefixLength: Minimum number of characters that must be entered before getting
suggestions from a web service.
 CompletionInerval: Time in milliseconds when the timer will kick in to get a suggestion using the
web service.
 ServiceMethod: The web service method to be called.
 FirstRowSelected: Whether the first row is selected from the suggestion.
Example:
<asp:ScriptManager ID="ScriptManager1" runat="server" EnablePageMethods="true">
</asp:ScriptManager>
<asp:AutoCompleteExtender ServiceMethod="GetSearch" MinimumPrefixLength="1"
CompletionInterval="10" EnableCaching="false" CompletionSetCount="10"
TargetControlID="TextBox1" ID="AutoCompleteExtender1" runat="server"
FirstRowSelected="false">
</asp:AutoCompleteExtender>
<asp:Label ID="Label1" runat="server" Text="Search Name"></asp:Label>
106
<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
Source Code:
[System.Web.Script.Services.ScriptMethod()]
[System.Web.Services.WebMethod]
public static List<string> GetSearch(string prefixText)
{
SqlConnection con = new SqlConnection("connectionString"); //Create a Sql connection
SqlDataAdapter da;
DataTable dt;
DataTable Result = new DataTable();
string str = "select nvName from Friend where nvName like '" + prefixText + "%'";
da = new SqlDataAdapter(str, con);
dt = new DataTable();
da.Fill(dt);
List<string> Output = new List<string>();
for (int i = 0; i < dt.Rows.Count; i++)
Output.Add(dt.Rows[i][0].ToString());
return Output;
}

107

You might also like