Nov 20 2008
Posted by Boyan Mihailov in ASP.NET
Custom server controls do great job. A complex page can easily be split into many controls. In this way it becomes easier to support after that. Used in a page, a server control follows the whole page life cycle.
Sometimes you will need just to get the HTML output from a server control for a different usage like sending it by an e-mail. So what can you do? There is a method called RenderControl, which renders a control using a HtmlTextWriter object. We can simply load the control using the LoadControl method and then use RenderControl.
Control myControl = LoadControl("~/MyControl.ascx");
StringBuilder sb = new StringBuilder();
using (StringWriter sw = new StringWriter(sb))
{
using (HtmlTextWriter tw = new HtmlTextWriter(sw))
{
myControl.RenderControl(tw);
}
}
Console.WriteLine(sb);
But the output is not what we really want. It contains only the static HTML tags. The server controls inside our control are not rendered. Why? Because in our way, the control does not follow the page life cycle. So, what we should do is to add it to a page.
Page page = new Page();
Control myControl = LoadControl("~/MyControl.ascx");
StringBuilder sb = new StringBuilder();
page.Controls.Add(myControl);
using (StringWriter sw = new StringWriter(sb))
{
Server.Execute(page, sw, false);
}
Console.WriteLine(sb);
Server.Execute method executes an IHttpHandler object and writes the output using a TextWriter object. In this way we follow the whole page life cycle so our control will render everything inside it.
New great debugging tool has come to the web. Crack .NET allows you to go through the managed heap of your Windows Desktop application (Windows Forms or WPF) and see what it contains. Not only you can see what’s inside, but you can modify it using IronPython scripts.
Silverlight Write & Win Contest was carried out for the second time. It is a interesting contest. You only have to write an article about Silverlight (application, control, game, web services, Blend, design, example, problem solution, etc). The first contest was organized by Michael Sync. Now, SilverlightShow take this initiative. They really did a great job in the organization.
I took part in the first edition, so I decided to write an article for this one, too. And I got it! I won the third prize, which looks like this:
Cool, right? The one who get the first prize is Alexey Zakharov with his article - Virtual earth deep zooming.
SilverlightShow announced that they intend to organize another contest, so I am waiting for it.
Every programming language has its own coding style. It is very essential that every developer, who uses the language, keeps to its style. When a team of developers work over a project, they should be able to read easily the code written by everyone in the team. It does make sense how the code is written!
Here are some coding rules, when using C#:
Good:
if (name == String.Empty) { // do something }
Bad:
if (name == "") { // do something }
if (name.ToLower() == "john") { //… }
StyleCop analyzes C# source code to enforce a set of style and consistency rules. It can be run from inside of Visual Studio or integrated into an MSBuild project. Don’t hesitate and download this great tool!
Good news for the Silverlight fans - the first Silverlight release candidate is released. Note that this is not the final runtime, it is developer only. It is released to let developers get into the changes and reform their Silverlight beta 2 applications. There are some breaking changes between Beta2 and this RC. You can take a look at this great article for most of them. As such, you can only use the RC for development right now - you can’t go live with the new APIs until the final release is shipped (which will be soon though).
You can download today’s Silverlight Release Candidate and accompanying VS and Blend support for it here. Note that Expression Blend support for Silverlight 2 is now provided using Blend 2.0 SP1. You will need to install Blend 2.0 before applying the SP1 service pack that adds Silverlight 2 support. If you don’t already have Blend 2.0 installed you can download a free trial of it here. Read the rest of this entry »
| M | T | W | T | F | S | S |
|---|---|---|---|---|---|---|
| « Nov | ||||||
| 1 | 2 | 3 | 4 | 5 | ||
| 6 | 7 | 8 | 9 | 10 | 11 | 12 |
| 13 | 14 | 15 | 16 | 17 | 18 | 19 |
| 20 | 21 | 22 | 23 | 24 | 25 | 26 |
| 27 | 28 | 29 | 30 | 31 | ||