AWP Unit 5
AWP Unit 5
com
Acuity Educare
ADVANCED WEB
PROGRAMMING
SEM : V
SEM V: UNIT 5
Page 1 of 19
YouTube - Abhay More | Telegram - abhay_more
607A, 6th floor, Ecstasy business park, city of joy, JSD road, mulund (W) | 8591065589/022-25600622
TRAINING -> CERTIFICATION -> PLACEMENT BSC IT : SEM – V AWP:UNIT5
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){ }
}
Page 2 of 19
YouTube - Abhay More | Telegram - abhay_more
607A, 6th floor, Ecstasy business park, city of joy, JSD road, mulund (W) | 8591065589/022-25600622
TRAINING -> CERTIFICATION -> PLACEMENT BSC IT : SEM – V AWP:UNIT5
}
protected void BindDataToGridview()
{
XmlTextReader xmlreader = new
Page 3 of 19
YouTube - Abhay More | Telegram - abhay_more
607A, 6th floor, Ecstasy business park, city of joy, JSD road, mulund (W) | 8591065589/022-25600622
TRAINING -> CERTIFICATION -> PLACEMENT BSC IT : SEM – V AWP:UNIT5
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();
}
}
Page 4 of 19
YouTube - Abhay More | Telegram - abhay_more
607A, 6th floor, Ecstasy business park, city of joy, JSD road, mulund (W) | 8591065589/022-25600622
TRAINING -> CERTIFICATION -> PLACEMENT BSC IT : SEM – V AWP:UNIT5
Page 5 of 19
YouTube - Abhay More | Telegram - abhay_more
607A, 6th floor, Ecstasy business park, city of joy, JSD road, mulund (W) | 8591065589/022-25600622
TRAINING -> CERTIFICATION -> PLACEMENT BSC IT : SEM – V AWP:UNIT5
}
}
Page 6 of 19
YouTube - Abhay More | Telegram - abhay_more
607A, 6th floor, Ecstasy business park, city of joy, JSD road, mulund (W) | 8591065589/022-25600622
TRAINING -> CERTIFICATION -> PLACEMENT BSC IT : SEM – V AWP:UNIT5
Page 7 of 19
YouTube - Abhay More | Telegram - abhay_more
607A, 6th floor, Ecstasy business park, city of joy, JSD road, mulund (W) | 8591065589/022-25600622
TRAINING -> CERTIFICATION -> PLACEMENT BSC IT : SEM – V AWP:UNIT5
</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();
xslt.Load(xsltFile);
Page 8 of 19
YouTube - Abhay More | Telegram - abhay_more
607A, 6th floor, Ecstasy business park, city of joy, JSD road, mulund (W) | 8591065589/022-25600622
TRAINING -> CERTIFICATION -> PLACEMENT BSC IT : SEM – V AWP:UNIT5
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.
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” />
Page 9 of 19
YouTube - Abhay More | Telegram - abhay_more
607A, 6th floor, Ecstasy business park, city of joy, JSD road, mulund (W) | 8591065589/022-25600622
TRAINING -> CERTIFICATION -> PLACEMENT BSC IT : SEM – V AWP:UNIT5
Page 10 of 19
YouTube - Abhay More | Telegram - abhay_more
607A, 6th floor, Ecstasy business park, city of joy, JSD road, mulund (W) | 8591065589/022-25600622
TRAINING -> CERTIFICATION -> PLACEMENT BSC IT : SEM – V AWP:UNIT5
(Role-based security is an optional higher-level feature we can use with forms authentication.
Page 11 of 19
YouTube - Abhay More | Telegram - abhay_more
607A, 6th floor, Ecstasy business park, city of joy, JSD road, mulund (W) | 8591065589/022-25600622
TRAINING -> CERTIFICATION -> PLACEMENT BSC IT : SEM – V AWP:UNIT5
Q. 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.
Page 12 of 19
YouTube - Abhay More | Telegram - abhay_more
607A, 6th floor, Ecstasy business park, city of joy, JSD road, mulund (W) | 8591065589/022-25600622
TRAINING -> CERTIFICATION -> PLACEMENT BSC IT : SEM – V AWP:UNIT5
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.
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.
Page 13 of 19
YouTube - Abhay More | Telegram - abhay_more
607A, 6th floor, Ecstasy business park, city of joy, JSD road, mulund (W) | 8591065589/022-25600622
TRAINING -> CERTIFICATION -> PLACEMENT BSC IT : SEM – V AWP:UNIT5
</ProgressTemplate>
</asp:UpdateProgress>
Page 14 of 19
YouTube - Abhay More | Telegram - abhay_more
607A, 6th floor, Ecstasy business park, city of joy, JSD road, mulund (W) | 8591065589/022-25600622
TRAINING -> CERTIFICATION -> PLACEMENT BSC IT : SEM – V AWP:UNIT5
Page 15 of 19
YouTube - Abhay More | Telegram - abhay_more
607A, 6th floor, Ecstasy business park, city of joy, JSD road, mulund (W) | 8591065589/022-25600622
TRAINING -> CERTIFICATION -> PLACEMENT BSC IT : SEM – V AWP:UNIT5
Page 16 of 19
YouTube - Abhay More | Telegram - abhay_more
607A, 6th floor, Ecstasy business park, city of joy, JSD road, mulund (W) | 8591065589/022-25600622
TRAINING -> CERTIFICATION -> PLACEMENT BSC IT : SEM – V AWP:UNIT5
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).
AccordionPane contains two parts i.e. Header and Content. When AccordionPane is
collapsed, only Header part is visible to us.
Page 17 of 19
YouTube - Abhay More | Telegram - abhay_more
607A, 6th floor, Ecstasy business park, city of joy, JSD road, mulund (W) | 8591065589/022-25600622
TRAINING -> CERTIFICATION -> PLACEMENT BSC IT : SEM – V AWP:UNIT5
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>
<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++)
Page 18 of 19
YouTube - Abhay More | Telegram - abhay_more
607A, 6th floor, Ecstasy business park, city of joy, JSD road, mulund (W) | 8591065589/022-25600622
TRAINING -> CERTIFICATION -> PLACEMENT BSC IT : SEM – V AWP:UNIT5
Output.Add(dt.Rows[i][0].ToString());
return Output;
}
Page 19 of 19
YouTube - Abhay More | Telegram - abhay_more
607A, 6th floor, Ecstasy business park, city of joy, JSD road, mulund (W) | 8591065589/022-25600622