background preloader

ASP.NET

Facebook Twitter

ASP.NET tutorials

HTML / CSS. Web hosting. Entity Framework. W3Schools Online Web Tutorials. ASP.NET Examples. ASP.NET Web Server Controls. Home : Official Microsoft Site. Getting your data out of the data controls - Unhandled Exception. After you've created a layout with a data control of your choice and eventually bound them to some datasource, you almost always want to get that data back out of them(and why wouldn't you, its your data). One thing you'll learn about developing asp.net webpages is that its like petting a porcupine (yikes). If you go with the flow, you probably won't get stuck, but the moment you try to go against the grain you end up with a hand full of thorns. Most of the data controls have events ending in ing and ed e.g. RowUpdating, RowUpdated etc. In most of the event handlers of the ing events it is easy to get the values from the event args. private void OnGridViewRowUpdating(object sender, GridViewUpdateEventArgs e) { IDictionary keys = e.Keys; IDictionary newValues = e.NewValues; IDictionary oldValues = e.OldValues; Forgive me for the variation in my code formatting I'm trying to find the right one.

Going Hunting in the Control Tree This is probably one of the worst things you can do. Return values; ASP.NET Page Life Cycle Overview. The topic you requested is included in another documentation set. For convenience, it's displayed below. Choose Switch to see the topic in its original location. Updated: May 2011 When an ASP.NET page runs, the page goes through a life cycle in which it performs a series of processing steps. These include initialization, instantiating controls, restoring and maintaining state, running event handler code, and rendering. It is important for you to understand the page life cycle so that you can write code at the appropriate life-cycle stage for the effect you intend. If you develop custom controls, you must be familiar with the page life cycle in order to correctly initialize controls, populate control properties with view-state data, and run control behavior code.

This topic contains the following sections: Within each stage of the life cycle of a page, the page raises events that you can handle to run your own code. Nested Data-Bound Controls Reference Concepts Other Resources. ASP.NET Web Server Control Event Model. Binding Control Events Private Sub ButtonClick(ByVal sender As System.Object, _ ByVal e As System.EventArgs) Handles SampleButton.Click Binding Page Events ASP.NET pages raise life-cycle events such as Init, Load, PreRender, and others. By default, you can bind page events to methods using a naming convention of Page_eventname. For example, to create a handler for the page's Load event, you can create a method named Page_Load. Sub MyPageLoad(sender As Object, e As EventArgs) Handles MyBase.Load One disadvantage of the AutoEventWireup attribute is that it requires that the page event handlers have specific, predictable names.

Explicit Binding for Dynamic Controls Button b = new Button; b.Text = "Click"; b.Click += new System.EventHandler(ButtonClick); Placeholder1.Controls.Add(b); C# Razor Syntax Quick Reference. I gave a presentation to another team at Microsoft yesterday on ASP.NET MVC and the Razor view engine and someone asked if there was a reference for the Razor syntax. It turns out, there is a pretty good guide about Razor available, but it’s focused on covering the basics of web programming using Razor and inline pages and not just the Razor syntax. So I thought it might be handy to write up a a really concise quick reference about the Razor syntax. Notice in the “mixing expressions and text” example that Razor is smart enough to know that the ending period is a literal text punctuation and not meant to indicate that it’s trying to call a method or property of the expression. Let me know if there are other examples you think should be placed in this guide.

I hope you find this helpful. UPDATE 12/30/2012:I’ve added a few new examples to the table of new additions to Razor v2/ASP.NET MVC 4 syntax. Also, if you want to know more, consider buying the Progamming ASP.NET MVC 4 book.

WebForms

MVC3+