Sunday, 24 June 2012

What is DLL(Dynamic Link Library)? Dll file in app_data folder in asp.net visual studio...how it works,how it creates...



Stands for "Dynamic Link Library." A DLL (.dll) file contains a library of functions and other information that can be accessed by a Windows program.

When a program is launched, links to the necessary .dll files are created.

If a static link is created, the .dll files will be in use as long as the program is active.

If a dynamic link is created, the .dll files will only be used when needed.

Dynamic links help programs use resources, such as memory and hard drive space, more efficiently.

Saturday, 23 June 2012

Introduction to XML :xml in asp.net with exampale




XML stands for Extensible Markup Language. An XML document stores data in the form of text. The data itself can be textual or binary. The binary data is not stored as binary data but is first converted to and is stored as text data. Elements and attributes are used in XML document to encapsulate data in a more logical hierarchical fashion.

This tutorial is 1st one in the series of tutorials about XML and ASP.NET:

Sample XML Document

Following is a simple XML document:

<?xml version="1.0" encoding="utf-8"?>
<article>
<author isadmin="true">Faisal Khan</author>
<title>Sample XML Document</title>
<body>The body of the article goes here.</body>
</article>

XML Declaration
All XML documents start with . This tells the XML parser that what is to follow is an XML document. An optional encoding attribute is often added as well.

<?xml version="1.0" encoding="utf-8"?>
<article>
<author isadmin="true">Faisal Khan</author>
<title>Sample XML Document</title>
<body>The body of the article goes here.</body>
</article>


Storing Data in an XML Document
The XML document contains text data that is held in its place by a logical hierarchy of elements. The data in the sample XML document, above, is highlighted below:


<?xml version="1.0" encoding="utf-8"?>
<article>
    <author isadmin="true">Faisal Khan</author>
    <title>Sample XML Document</title>
    <body>The body of the article goes here.</body>
</article>


Elements
All XML documents must have a root element. In our sample XML document, the root element is article. All elements must have a starting tag and an ending tag. The name of the element can be anything you want. But it is recommended to keep the element names short and simple to understand e.g., article, full_name, first_name, etc. If an element name has to consist of two words, it is recommended to insert an '_' (underscore) character in the place of space e.g., first_name for "first name". An element is contained between < and > characters. The ending tag has an additional slash '/' just before the name of the element.

The elements in the sample XML document are highlighted below:


<?xml version="1.0" encoding="utf-8"?>
<article>
<author isadmin="true">Faisal Khan</author>
<title>Sample XML Document</title>
<body>The body of the article goes here.</body>
</article>
 
 

Attributes
An attribute is name/value pair within an element that can store further information for an element. It has to be in the format of name="value". In our XML document, isadmin is the name of the attribute within author element, whose value is "true". The attribute in our XML document is highlighted below:


<?xml version="1.0" encoding="utf-8"?>
<article>
<author isadmin="true">Faisal Khan</author>
<title>Sample XML Document</title>
<body>The body of the article goes here.</body>
</article>

Entity References
Certain characters are illegal to be present in data segments of the elements i.e., between element start and end tags. These characters are &, <, >, ', and ". The reason is that they have special meaning in an XML document. As you read above, XML elements and attributes use these characters to encapsulate data. Now what should you do if you want to use these characters as data in an XML document? Well, make use of entity references.

An "entity" is a name/value pair defined in a DTD (Document Type Definition) file. We will learn more about DTD files later. For now, you should know that an entity can be a name/value pair, just like an attribute, which you can define yourself. While attributes are defined in XML documents, entities (1 ore more) are defined inside DTD files. You can define an entity in an XML document using DTD syntax and make use of it later in the data in your XML document using an entity reference who syntax is: &entityName;. This is dynamic

substitution. The XML parser will replace the entity reference at runtime with the value of that entity.

<!ENTITY websiteName "Stardeveloper.com">

Above code defines an entity "websiteName" with the value, "Stardeveloper.com". You can access the value of this entity using an entity reference within your XML document using the syntax &websiteName; as shown below:

<?xml version="1.0" encoding="utf-8"?>
<article>
    <author isadmin="true">Faisal Khan</author>
    <title>Sample XML Document</title>
    <body>This article will be posted at &websiteName;.</body>
</article>



Now that you know what entities are and how entity references can be used to access their values inside the data portions of an XML document, dynamically; you should know that all XML documents can use 5 pre-loaded entity references as given below:
Character Entity Reference
& &amp;
< &lt;
> &gt;
' &apos;
" &quot;
Now, if you want to use any of the 5 special characters as data in your XML document, you can use them using entity references like this:

<?xml version="1.0" encoding="utf-8"?>
<article>
<author isadmin="true">Faisal Khan</author>
<title>Sample XML Document</title>
<body>Now you can use &amp;, &lt;, &gt;, &apos;, and &quot;
tags as often as you want.</body>
</article>


Reading XML Files with ASP.NET example...XML file call using asp.net



In this tutorial, we will learn how to read the contents of an XML file with ASP.NET.

We will make use of the sample XML file which we created in the previous tutorial (Introduction to XML). We will create an ASP.NET page which reads the contents of this XML file and then displays it to the user.

Sample XML File


Okay, let us get started now. Copy and paste the contents below in a new text file and then save that file as "sample.xml" in the



/App_Data sub-folder of your ASP.NET web application.

you see App_Data after create a new database..

Placing the XML file in /App_Data sub-folder ensures that no one will be able to directly access this file from the web. It will only be accessed by our ASP.NET page which will read and display its contents.

<?xml version="1.0" encoding="utf-8"?>
<article>
    <author isadmin="true">Faisal Khan</author>
    <title>Sample XML Document</title>
    <body>The body of the article goes here.</body>
</article>

Reading the Contents of XML File using XmlDocument class

System.Xml namespace has a class with the name of XmlDocument which we will use to read XML file's contents and display it to the user.

Reading the contents of sample.xml file is as easy as these two lines:

XmlDocument doc = new XmlDocument();
doc.Load(Server.MapPath("~/App_Data/sample.xml"));






Before we delve ourselves deeper into the code, we should create the ASP.NET page first and study its code later.

Reader.aspx
Copy and paste following code into an ASP.NET page and then save it as "reader.aspx":

<%@ Page Language="C#" AutoEventWireup="true" %>

<%@ Import Namespace="System.Xml" %>

<script runat="server">
protected void Page_Load(object source, EventArgs e)
{
XmlDocument doc = new XmlDocument();
doc.Load(Server.MapPath("~/App_Data/sample.xml"));

XmlNode root = doc.DocumentElement;
AuthorLiteral.Text = root.SelectSingleNode("author").ChildNodes[0].Value;
TitleLiteral.Text = root.SelectSingleNode("title").ChildNodes[0].Value;
BodyLiteral.Text = root.SelectSingleNode("body").ChildNodes[0].Value;
}
</script>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title>Reading an XML File</title>
<style type="text/css">
body { font-family: Verdana; font-size: 9pt; }
.name { background-color: #F7F7F7; }
</style>
</head>
<body>
<form id="form1" runat="server">
<div>
<table width="50%" cellpadding="5" cellspacing="2">
<tr>
<td class="name">Name</td>
<td><asp:Literal ID="AuthorLiteral" runat="server" />
<asp:Literal ID="AdminLiteral" runat="server" /></td>
</tr>
<tr>
<td class="name">Title</td>
<td><asp:Literal ID="TitleLiteral" runat="server" /></td>
</tr>
<tr>
<td class="name">Body</td>
<td><asp:Literal ID="BodyLiteral" runat="server" /></td>
</tr>
</table>

</div>
</form>
</body>
</html>


When you have properly placed sample.xml file in /App_Data sub-folder and reader.aspx in your web application; you should run the ASP.NET page by accessing it in your browser. On my computer, the ASP.NET page, when run, looked like this:






Now that we have created the ASP.NET which successfully reads and displays the contents of our XML file, we should look at the code which is doing the job.


explain xml in asp.net : where XML is Used?,HOW xml is Use,....XML with an example..



1st.use..

You can use XMl to import data into your system and Export out of the system.

This will make you application easier to interact with other application written in different languages.

It depends on a Developer too, some prefer to bind grid with XML and some choose with objects.

2nd use of XML with Example..

Assume am validating a ZIP code (Server Side) that ensures that the user entered ZIP code is available in my ZIPCodes table in some X database. ( An arbitrary business requirement).

Now assume I have 100,000 customers hitting my website every 2 hrs (not realistic but possible. Consider this scenario for the reasons of explanation).

The database may get hammered 100,000 times every 2 hrs. The database may also need to serve other requests apart from the one under discussion.

So, database is a busy for most of the time.

Presuming that ZIPCodes dont change often or they dont change for ever, I would export the ZipCodes to an XML file and have it somewhere secure as part of the web-application.

Now, the validation is done against the XML file and not the database.

So, we might endup eliminating 100,000 hits to the database, in which case the database is open to serve other requests.

There are other possible uses too! But this should just give you a jist of the power xml has.

What are SSI? ssi in asp.net ...use of SSI?



SSI (Server Side Includes) are directives that are placed in HTML pages,

and evaluated on the server while the pages are being served.

They let you add dynamically generated content to an existing HTML page, without having to serve the entire page via a CGI program, or other dynamic technology.

The decision of when to use SSI, and when to have your page entirely generated by some program, is usually a matter of how much of the page is static, and how much needs to be recalculated every time the page is served.

SSI is a great way to add small pieces of information, such as the current time. But if a majority of your page is being generated at the time that it is served, you need to look for some other solution.

What's the deal with Databinder.Eval and Container.DataItem?



The databinding expression <%# some expression %> is evaluated in the language of the page (VB, C#, etc.) This can have a big impact on the current syntax, so be very careful when you are looking at docs for the language you are using.



Container.DataItem is a runtime alias for the DataItem for this specific item in the bound list.

For a grid which displays 10 rows of data, this is one row from the datasource. The actual type of DataItem is determined by the type of the datasource.

For example, if the datasource is a Dataview, the type of DataItem is DataRowView. If the type of the datasource is an array of strings, the type of DataItem is String.

If the datasource is a collection of strongly-typed objects (for example "Employees" objects), the type of DataItem is Employees.



Each of these cases requires a slightly different databinding expression, with further differences between VB and C#.

In every case, you want the databinding expression to produce a string that can be displayed in the page.



Here are some examples:



Array of Strings:

VB/C# <%# Container.DataItem %>



Field from DataView:

VB <%# Container.DataItem("EmployeeName") %>

C# <%# ((DataRowView)Container.DataItem)["EmployeeName"] %>



Property from a collection of objects:

VB <%# Container.DataItem.CustomerName %>

C# <%# ((Customer)Container.DataItem).CustomerName %>



Non-String property from a collection of objects:

VB <%# CStr(Container.DataItem.CustomerID) %>

C# <%# ((Customer)Container.DataItem).CustomerID.ToString() %>





As you can see the syntax is tricky, especially for C#, which requires explicit casting. So we've provided a DataBinder.Eval() helper method that figures out the syntax for you and formats the result as a string.

It's really convenient, with a couple of caveats:

it's late bound (uses reflection at runtime to figure out the data types), and it only supports basic data types in the fields: string, int, datetime, etc.

You can use Eval instead of DataBinder.Eval in ASP.net 2.0



DataBinder.Eval takes 2 or 3 arguments.

The first arg is the data object to bind to. In the case of DataGrid, DataList and Repeater, Container.DataItem is the single row.

The second arg the string name of the field from the data object you which to display. DataBinder.Eval uses these two pieces of information to work out the rest of the expression syntax.



An optional third argument is a .NET formatting string. DataBinder.Eval will handle a single replacement for {0} only. So the example below:






could be simplified to:






Wrapping DataBinder.Eval in CStr() is unnecessary as the compiler will wrap the statement with a Convert.ToString like this:

control1.SetDataBoundString(0, Convert.ToString(DataBinder.Eval(item1.DataItem, "ID")));



Best of all, the Databinder.Eval syntax is the same for VB and C#.


Thursday, 21 June 2012

Events in asp.net : how to call event in asp.net,how to use event..



ASP.NET is an event-driven way of making web applications.

With PHP and Classic ASP,

you have one file, which is executed line after line, from start to end.

However, ASP.NET is very different.

Here we have events, which are either activated by the user in one way or another. In the previous example, we used the Page_Load method. Actually, this is an event, which the Page class calls when the page is loaded.

We will use the same technique in the next example, where we will add a couple of controls to our simple hello world example.

To make it a bit more interesting, we will change the "world" word with something defined by the user. Have a look at this codelisting, where we add two new controls: A Button control and a TextBox control.

<form id="form1" runat="server">
<div>
<asp:Label runat="server" id="HelloWorldLabel"></asp:Label>
<br /><br />
<asp:TextBox runat="server" id="TextInput" />
<asp:Button runat="server" id="GreetButton" text="Say Hello!" />
</div>
</form>


As you can see, we now have the 2 new controls added, but they really can't do much at the moment.

You can run the example if you wish to check this out for your self - if you click the button, the page is simply reloaded.

Let's change that, and let's start by doing it the easy way.

VWD comes with a WYSIWYG editor, and while I hardly ever use it my self, it does make some things easier, like creating events.

So, click the Design button in the bottom of VWD. Now you will see a visual representation of our page.

We wish to add a Click event to the button, and this is very simply - just doubleclick the GreetButton, and you will be taken to the CodeBehind file of our page.

As you can see, a fine new method has been added, called GreetButton_Click.

If you have a look at the Default.aspx file (you need to go from Design view to Source view), you will see that an attribute has been added to our Button control, telling which method to call when the button is clicked.

All this work done with a simple doubleclick.

Now lets add some code to our new event. We wish to use the text from the TextBox, on our good old Label with the "Hello, world!" text. This is also very simple, and all it requires is a single line of code:

HelloWorldLabel.Text = "Hello, " + TextInput.Text;


Run the project again (F6), and you will see the our old page with a couple of new controls. The "Hello, world!" text is still there, because we set it in the Page_Load event.

Now try entering a name in the textbox, and press the button. Voila, the text is changed, and we have just used our first control event.

Notice how we can add code which is not necessarily called unless the user performs a specific task. This is different from the good old Classic ASP/PHP approach, but you will soon get used to it, and you will probably also come to like it a lot!

source..

http://asp.net-tutorials.com/basics/events/