Navigation New In Silverlight 3

Monday, July 27, 2009



As Silverlight moves from providing controls and UX bits to providing a framework for creating entire applications, it becomes more important to have a framework for multi-“page” applications. Silverlight 3 introduces the Silverlight Navigation Application


This template in Visual Studio creates a series of files that serve as a very flexible and customizable framework for multi-page applications. The unmodified user experience, out of the box, is shown in this live demo, followed by a brief analysis of the code that Visual Studio creates.


(Note that I did modify the size to fit this page.) Visual Studio creates the usual MainPage.xaml/...cs and App.xaml/...cs files but also creates an Assets folder, containing Styles.xaml and a Views folder containing three starter pages:
Home.xaml
About.xaml
ErrorWindow.xaml
Each with its own code-behind.

You’ll notice that if you click on about the page switches, while the frame around the page does not.

Frame and URI Mapping
I’ll go into the details in an upcoming mini-tutorial and video, but the basic structure is that MainFrame.xaml provides an instance of System.Windows.Controls.Frame (found in the d System.Windows.Controls.Navigation namespace). The Frame supports navigation among pages, and also supports passing information to the page to tell it what state it should be in.

Rather than forcing you to provide a full path to the page, the Frame class allows you to request the page you want with an instance of URIMapping, which in turn provides support for parameterized URIs that request a page by mapping parameters to a full URI.

For example, your frame might contain a URIMapping that looks like this:





Uri="/ProductDetail/{productid}" MappedUri="/Views/ProductDetail.xaml?ProductId={productid}"/> 10:

You can see that this allows you to bring up a Product Detail page based on the provided ProductID and a second page based on whatever name is provided.

Download Source Code
thank you usama khan

Silverlight Retrieve Data and Populate in DataGrid from Networking

Silverlight 2 has built-in networking APIs that enable Silverlight clients to call remote REST, SOAP/WS*, RSS, JSON and XML HTTP services. Silverlight 2 also includes a built-in sockets API (System.Net.Sockets) that enables Silverlight clients to communicate over non-HTTP protocols (ideal for scenarios like chat servers, etc).

Cross Domain Network Access

Silverlight 2 applications can always call back to their "origin" server when making network calls (meaning they can call URLs on the same domain that the application was downloaded from). Silverlight 2 applications can also optionally make cross-domain network calls (meaning they can call URLs on different domains from where the application was downloaded from) when the remote web server has an XML policy file in place that indicates that clients are allowed to make these cross-domain calls.

Silverlight 2 defines an XML policy file format that allows server administrators to precisely control what access a client should have. Silverlight 2 also honors the default Flash cross domain policy file format - which means that you can use Silverlight 2 to call any existing remote REST, SOAP/WS*, RSS, JSON or XML end-point on the web that already enables cross-domain access for Flash clients.

Digg.com has a pretty cool set of Digg APIs that they publish over HTTP. Because they have a Flash cross-domain policy file in place on their server, we can call them directly from our Silverlight Digg client application (and not require us to tunnel back through our web-server to reach their APIs).

Digg.com Topic Feed API

We want to enable end-users using our application to type in a search topic (for example: "Programming") and then click the "Search" button to pull back the top stories from Digg.com that match it:



We can use the Digg.com List Stories REST API feed API to-do this. It takes a topic parameter in its URL (for example: GET /stories/topic/programming), and then returns back an XML payload of Digg stories that match that topic. Click here to see an example of what this XML looks like.

Using System.Net.WebClient to Asynchronously Call the Digg REST Feed

When the SearchButton is clicked above, we'll handle its "Click" event, retrieve the topic string to search for from the TextBox control, and then initiate a network call to Digg to retrieve the XML listing for that topic.

Silverlight includes the WebClient helper class within the System.Net namespace (this is also in the full .NET Framework). We can use this class to asynchronously download content from a URL. The benefit of downloading our Digg stories asynchronously is that our UI will not block or become unresponsive while waiting on the remote server (allowing us to have a very fluid user experience).

All we need to-do to perform an async download with the WebClient class is to register a "DownloadStringCompleted" event handler method that will be invoked once the requested content has been downloaded, and then call the WebClient.DownloadStringAsync(url) helper method to initiate the download:



And with the code above we can now asynchronously retrieve a string of XML data that contains the Digg stores about any topic a user wants.

Using LINQ to XML to Parse Digg XML Stories into Story Classes
Now that we can retrieve an XML snippet back of Digg story data, our next step will be to parse and convert it into "DiggStory" objects that we can manipulate and databind our controls against.

We'll do this by first defining a "DiggStory" class that has properties that map to the XML content from Digg (we'll take advantage of the new C# "automatic properties" feature to-do this):



We can then use LINQ (which is built-into Silverlight 2) and LINQ to XML (which is an extra library we can include with our Silverlight application) to easily parse and filter the XML document that was returned from Digg, and translate it into a sequence of "DiggStory" objects using the code below:



Notice above how we now have strongly typed DiggStory objects from our XML that we can work against.

Displaying our Digg Stories in a DataGrid Control
We'll use the Silverlight DataGrid control to display the Digg stories in our application. To enable this we'll reference the Silverlight Data controls assembly, and then replace our previous "Todo" text on the page with a DataGrid control declaration (note: you can double click on the "datagrid" control in the toolbox to automatically add one to the page):



The DataGrid allows you to explicitly configure column declarations and display types (for maximum control). Alternatively if you do not specify these, the DataGrid control will use reflection on its datasource to create default columns for you based on the schema of your objects.

We'll then update our code-behind class to programmatically bind the "ItemSource" property of the DataGrid to the sequence of stories we receive back from Digg when the search button is clicked :And now when we run our Silverlight application and do a search, we'll see a listing of live topic story data pulled from Digg:The Silverlight Datagrid supports all the standard features you expect with a client-side grid control: two way in-place editing, selection, scrolling, column resizing, column re-ordering, etc. It also supports auto-flow layout, which means it can dynamically expand or shrink to fill the content container it is in. The DataGrid also has a rich templating model that allows you to customize both the display and editing of column data.

Next Steps
We can now retrieve Digg story data from Digg.com and display the story data within our application.

Our next step will be to go back to our Page.xaml markup and remove the in-line style declarations we are currently using there.

Edit Template Grid View Databinding

Sunday, July 26, 2009



he GridView is composed of a set of fields that indicate what properties from the DataSource are to be included in the rendered output along with how the data will be displayed. The simplest field type is the BoundField, which displays a data value as text. Other field types display the data using alternate HTML elements. The CheckBoxField, for example, renders as a checkbox whose checked state depends on the value of a specified data field; the ImageField renders an image whose image source is based upon a specified data field. Hyperlinks and buttons whose state depends on an underlying data field value can be rendered using the HyperLinkField and ButtonField field types.

While the CheckBoxField, ImageField, HyperLinkField, and ButtonField field types allow for an alternate view of the data, they still are fairly limited with respect to formatting. A CheckBoxField can only display a single checkbox, whereas an ImageField can only display a single image. What if a particular field needs to display some text, a checkbox, and an image, all based upon different data field values? Or what if we wanted to display the data using a Web control other than the CheckBox, Image, HyperLink, or Button? Furthermore, the BoundField limits its display to a single data field. What if we wanted to show two or more data field values in a single GridView column?

To accommodate this level of flexibility the GridView offers the TemplateField, which renders using a template. A template can include a mix of static HTML, Web controls, and databinding syntax. Furthermore, the TemplateField has a variety of templates that can be used to customize the rendering for different situations. For example, the ItemTemplate is used by default to render the cell for each row, but the EditItemTemplate template can be used to customize the interface when editing data.

In this tutorial we'll examine how to use the TemplateField to achieve a greater degree of customization with the GridView control. In the preceding tutorial we saw how to customize the formatting based on the underlying data using the DataBound and RowDataBound event handlers. Another way to customize the formatting based on the underlying data is by calling formatting methods from within a template. We'll look at this technique in this tutorial as well.


Pleases Download Source Code and tutorial

Databind With ListView


HI
My Self Usama Wahab Khan Today will how to bind in asp.net
Setup by setup

1 Go Start Up Program Microsoft Visual Studio 2008

2 Go to File Tab and Click New Website

3 Select Asp.net Web Site and press OK

4 . Drag n drop ListView from toolbox on your form.
5. Add northwinds Sample database in your App_Data Folder
6. Click on Right Side of ListView Smart tag for ListView Tasks


7. Select Choose Data Source New DataSorces and Select SQL Data Sorces

8. Next and Select Customer Table check all fields .


9. Next Finished

10 Press F5.


PleaseDownload SorceCode with Sept by Sept tutorial
Thank you
Usama wahab khan
Software Developer
Usamawahabkhan.blogspot.com
lean free

GridView DataBinding



Databind in Asp.net is vary Easy so You Can Make Database Driven Website very Eeslly


Setup by setup
1 Go Start Up Program Microsoft Visual Studio 2008

2 Go to File Tab and Click New Website

3 Select Asp.net Web Site and press OK

4 . Drag n drop GridView from toolbox on your form.
5. Add northwinds Sample database in your App_Data Folder
6. Click on Right Side of Gridview Smart tag for GirdView Tasks


7. Select Choose Data Source New DataSorces and Select SQL Data Sorces

8. Next and Select Customer Table check all fields .


9. Next Finished

10 Press F5.

Please Download SorceCode with Sept by Sept tutorial
Thank you
Usama wahab khan
Software Developer
Usamawahabkhan.blogspot.com
lean free

OverView StateManagmnet Asp.net

Saturday, July 25, 2009

ASP.NET State Management Overview
A new instance of the Web page class is created each time the page is posted to the server. In traditional Web programming, this would typically mean that all information associated with the page and the controls on the page would be lost with each round trip. For example, if a user enters information into a text box, that information would be lost in the round trip from the browser or client device to the server.
To overcome this inherent limitation of traditional Web programming, ASP.NET includes several options that help you preserve data on both a per-page basis and an application-wide basis. These features are as follows:
• View state
• Control state
• Hidden fields
• Cookies
• Query strings
• Application state
• Session state
• Profile Properties
View state, control state, hidden fields, cookies, and query strings all involve storing data on the client in various ways. However, application state, session state, and profile properties all store data in memory on the server. Each option has distinct advantages and disadvantages, depending on the scenario.
Client-Based State Management Options
The following sections describe options for state management that involve storing information either in the page or on the client computer. For these options, no information is maintained on the server between round trips.
View State
The ViewState property provides a dictionary object for retaining values between multiple requests for the same page. This is the default method that the page uses to preserve page and control property values between round trips.
When the page is processed, the current state of the page and controls is hashed into a string and saved in the page as a hidden field, or multiple hidden fields if the amount of data stored in the ViewState property exceeds the specified value in the MaxPageStateFieldLengthproperty. When the page is posted back to the server, the page parses the view-state string at page initialization and restores property information in the page.
You can store values in view state as well. The following example shows how to store a value in the view state.
[Visual Basic]
ViewState("color") = "red"
[C#]
ViewState["color"] = "red";
For more information about using view state, see ASP.NET View State Overview. For recommendations about when you should use view state, see ASP.NET State Management Recommendations.
Control State
Sometimes you need to store control-state data in order for a control to work properly. For example, if you have written a custom control that has different tabs that show different information, in order for that control to work as expected, the control needs to know which tab is selected between round trips. The ViewState property can be used for this purpose, but view state can be turned off at a page level by developers, effectively breaking your control. To solve this, the ASP.NET page framework exposes a feature in ASP.NET called control state.
The ControlState property allows you to persist property information that is specific to a control and cannot be turned off like the ViewStateproperty.
The following example shows a custom control that stores a value in control state.
Visual Basic
Class Sample
Inherits Control

Dim currentIndex As Integer

Protected Overrides Sub OnInit(ByVal e As EventArgs)
Page.RegisterRequiresControlState(Me)
currentIndex = 0
MyBase.OnInit(e)
End Sub

Protected Overrides Function SaveControlState() As Object
If currentIndex <> 0 Then
Return CType(currentIndex, Object)
Else
Return Nothing
End If
End Function

Protected Overrides Sub LoadControlState(ByVal state As Object)
If (state <> Nothing) Then
currentIndex = CType(state, Integer)
End If
End Sub

End Class

C#
public class Sample : Control {
private int currentIndex = 0;

protected override void OnInit(EventArgs e) {
Page.RegisterRequiresControlState(this);
base.OnInit(e);
}

protected override object SaveControlState() {
return currentIndex != 0 ? (object)currentIndex : null;
}

protected override void LoadControlState(object state) {
if (state != null) {
currentIndex = (int)state;
}
}
}

For more information, see Control State vs. View State Example.
Hidden Fields
ASP.NET allows you to store information in a HiddenField control, which renders as a standard HTML hidden field. A hidden field does not render visibly in the browser, but you can set its properties just as you can with a standard control. When a page is submitted to the server, the content of a hidden field is sent in the HTTP form collection along with the values of other controls. A hidden field acts as a repository for any page-specific information that you want to store directly in the page.
Security Note:
It is easy for a malicious user to see and modify the contents of a hidden field. Do not store any information in a hidden field that is sensitive or that your application relies on to work properly. For more information, see ASP.NET State Management Recommendations.

A HiddenField control stores a single variable in its Value property and must be explicitly added to the page. The following example shows aHiddenField control with an initial value.
value="Example Value"
runat="server"/>
For more information, see HiddenField Web Server Control Overview.
In order for hidden-field values to be available during page processing, you must submit the page using an HTTP POST command. If you use hidden fields and a page is processed in response to a link or an HTTP GET command, the hidden fields will not be available. For usage recommendations, see ASP.NET State Management Recommendations.
Cookies
A cookie is a small amount of data that is stored either in a text file on the client file system or in-memory in the client browser session. It contains site-specific information that the server sends to the client along with page output. Cookies can be temporary (with specific expiration times and dates) or persistent.
You can use cookies to store information about a particular client, session, or application. The cookies are saved on the client device, and when the browser requests a page, the client sends the information in the cookie along with the request information. The server can read the cookie and extract its value. A typical use is to store a token (perhaps encrypted) indicating that the user has already been authenticated in your application.
Security Note:
The browser can only send the data back to the server that originally created the cookie. However, malicious users have ways to access cookies and read their contents. It is recommended that you do not store sensitive information, such as a user name or password, in a cookie. Instead, store a token in the cookie that identifies the user, and then use the token to look up the sensitive information on the server.
The following example shows how to write a cookie.
Visual Basic
Response.Cookies("destination").Value = "CA"
Response.Cookies("destination").Expires = DateTime.Now.AddDays(1)
C#
Response.Cookies["destination"].Value = "CA";
Response.Cookies["destination"].Expires = DateTime.Now.AddDays(1);
For more information about using cookies, see Cookies, ASP.NET Cookies Overview, and ASP.NET State Management Recommendations.
Query Strings
A query string is information that is appended to the end of a page URL. A typical query string might look like the following example:
http://www.contoso.com/listwidgets.aspx?category=basic&price=100
In the URL path above, the query string starts with a question mark (?) and includes two attribute/value pairs, one called "category" and the other called "price."
Query strings provide a simple but limited way to maintain state information. For example, they are an easy way to pass information from one page to another, such as passing a product number from one page to another page where it will be processed. However, some browsers and client devices impose a 2083-character limit on the length of the URL.
Security Note:
Information that is passed in a query string can be tampered with by a malicious user. Do not rely on query strings to convey important or sensitive data. Additionally, a user can bookmark the URL or send the URL to other users, thereby passing that information along with it. For more information, see ASP.NET State Management Recommendations and How to: Protect Against Script Exploits in a Web Application by Applying HTML Encoding to Strings.

In order for query string values to be available during page processing, you must submit the page using an HTTP GET command. That is, you cannot take advantage of a query string if a page is processed in response to an HTTP POST command. For usage recommendations, seeASP.NET State Management Recommendations.
Server-Based State Management Options
ASP.NET offers you a variety of ways to maintain state information on the server, rather than persisting information on the client. With server-based state management, you can decrease the amount of information sent to the client in order to preserve state, however it can use costly resources on the server. The following sections describe three server-based state management features: application state, session state, and profile properties.
Application State
ASP.NET allows you to save values using application state — which is an instance of the HttpApplicationState class — for each active Web application. Application state is a global storage mechanism that is accessible from all pages in the Web application. Thus, application state is useful for storing information that needs to be maintained between server round trips and between requests for pages. For more information, see ASP.NET Application State Overview.
Application state is stored in a key/value dictionary that is created during each request to a specific URL. You can add your application-specific information to this structure to store it between page requests.
Once you add your application-specific information to application state, the server manages it. For usage recommendations, see ASP.NET State Management Recommendations.
The following example shows how to assign a value in application state.
[Visual Basic]
Application("WelcomeMessage") = "Welcome to the Contoso site."
[C#]
Application["WelcomeMessage"] = "Welcome to the Contoso site.";
Session State
ASP.NET allows you to save values by using session state — which is an instance of the HttpSessionState class — for each active Web-application session. For an overview, see ASP.NET Session State Overview.
Session state is similar to application state, except that it is scoped to the current browser session. If different users are using your application, each user session will have a different session state. In addition, if a user leaves your application and then returns later, the second user session will have a different session state from the first.
Session state is structured as a key/value dictionary for storing session-specific information that needs to be maintained between server round trips and between requests for pages. For more information, see ASP.NET Session State Overview.
You can use session state to accomplish the following tasks:
• Uniquely identify browser or client-device requests and map them to an individual session instance on the server.
• Store session-specific data on the server for use across multiple browser or client-device requests within the same session.
• Raise appropriate session management events. In addition, you can write application code leveraging these events.
Once you add your application-specific information to session state, the server manages this object. Depending on which options you specify, session information can be stored in cookies, on an out-of-process server, or on a computer running Microsoft SQL Server. For usage recommendations, see ASP.NET State Management Recommendations.
The following example shows how to save a value in session state.
Visual Basic
Session("FirstName") = FirstNameTextBox.Text
Session("LastName") = LastNameTextBox.Text
C#
Session["FirstName"] = FirstNameTextBox.Text;
Session["LastName"] = LastNameTextBox.Text;
Profile Properties
ASP.NET provides a feature called profile properties, which allows you to store user-specific data. This feature is similar to session state, except that the profile data is not lost when a user's session expires. The profile-properties feature uses an ASP.NET profile, which is stored in a persistent format and associated with an individual user. The ASP.NET profile allows you to easily manage user information without requiring you to create and maintain your own database. In addition, the profile makes the user information available using a strongly typed API that you can access from anywhere in your application. You can store objects of any type in the profile. The ASP.NET profile feature provides a generic storage system that allows you to define and maintain almost any kind of data while still making the data available in a type-safe manner.
To use profile properties, you must configure a profile provider. ASP.NET includes a SqlProfileProvider class that allows you to store profile data in a SQL database, but you can also create your own profile provider class that stores profile data in a custom format and to a custom storage mechanism such as an XML file, or even to a web service.
Because data that is placed in profile properties is not stored in application memory, it is preserved through Internet Information Services (IIS) restarts and worker-process restarts without losing data. Additionally, profile properties can be persisted across multiple processes such as in a Web farm or a Web garden. For more information, see ASP.NET Profile Properties Overview.
The following example shows how to save a profile value.
Visual Basic
Profile.PostalCode = txtPostalCode.Text
C#
Profile.PostalCode = txtPostalCode.Text;
You must define the PostalCode property in the Web.config file by using the following markup:




Tree Double Click Event

Friday, July 24, 2009

1 Dran and Drop TreeView on YOur form
2 Selcet Treevrew and rightclick and go to Properties
3 Click the Event Icon on Top Properties Window
4 Double Click ON DoubleClick Event
5 Use With if check with your Condition
---- Now add Tree View Programmictlly and Register its Double Click Event
1 Add button contorl on your form
2 Add Panal Control
3 double click on button control and Right Code blow in your button Click Event
4

TreeView tr = new TreeView();
tr.Nodes.Add("Hello");
tr.Nodes.Add("Hello");
tr.Nodes.Add("Hello");
tr.Location = new Point(20, 10);
this.panel1.Controls.Add(tr);
tr.Visible = true;j

5 Register Treeview DoubleClick Event to Delates
tr.DoubleClick += new EventHandler(tr_DoubleClick);

6 add this Function to your Form Class


void tr_DoubleClick(object sender, EventArgs e)
{
MessageBox.Show("I am new Double Click");
}


Or AnyThing Else Just Contcat me
thank you
usama wahab khan
Download Now