Browse by Tags

All Tags » code (RSS)

HttpRequest Using IsAjax & IsJson Extension Methods by Palermo4

Although the ScriptManager has a property named IsInAsyncPostBack to determine an AJAX call, the control is scoped to the page it is contained in. If writing code in a custom HTTP module, what if I need to know in the BeginRequest event whether the current...

How To: Access Underlying Data of the ObjectDataSource by Palermo4

A gentleman in my ASP.NET 2.0 class a while ago asked me how to access the underlying object used for the ObjectDataSource control. Suppose you have some code in App_Code like so: public class DataManager { public DataSet SelectDataSet() { // code that...
Filed under: , , , ,

Revision: Get the Value of a Control Without an Instance of the Control by Palermo4

On an earlier post, I provided code that would retrieve the value of a control from the HTTP post without the need for an instance of the control . With good feedback, I made some modifications as follows: public static string GetControlValueFromRequest...
Filed under: , , ,

Revision: Case-Insensitive String Equality by Palermo4

I made revisions to my method for comparing strings while ignoring case . This is in light of some good feedback I received. Here is the updated method: public static bool AreEqualIgnoreCase( string firstString, string secondString) { // if references...
Filed under: , ,

To Compile or Not Compile by Palermo4

ASP.NET 2.0 allows developers to configure whether a page compiles or not. Consider the following page directive: <% @ Page Language ="C#" CompilationMode ="Never" %> Setting the CompilationMode attribute to Never will disallow code on the page...
Filed under: , ,

How To: Create a Strongly-Typed Property For HttpContext.Items by Palermo4

HttpContext.Items is one of my favorite properties in ASP.NET. If I want to communicate a value from the HTTP pipeline to a page and then to a user control, this is my method for doing so. Because the Items property is an implementation of IDictionary...
Filed under: , , ,

How To: "Upsert" Into AppSettings by Palermo4

ASP.NET 2.0 allows developers to update or insert values into web.config programmatically. This allows senior ASP.NET developers to create an administration or support page to modify values into web.config sections - without tampering with the web.config...
Filed under: , , ,

How To: Obtain Method Name Programmatically For Tracing by Palermo4

I am not a fan of hard-coding method names in exception or trace messages. Here is a utility method to allow access to method name at runtime: public static void TraceContext( string messageFormat) { Trace .WriteLine( string .Format(messageFormat, new...
Filed under: , , ,

How To: Return Embedded Resource Content As String by Palermo4

Here is a utility method for returning any embedded resource content as a string: public static partial class Tools { public static string GetEmbeddedContent( string resourceName) { Stream resourceStream = Assembly .GetAssembly( typeof ( Tools )).GetManifestResourceStream...
Filed under: , ,

How To: Dynamically Load A Page For Processing by Palermo4

I have often desired the ability to dynamically load a page for processing, much like we do for .asxc controls with LoadControl(pathToASCX). For example, I may want to create a custom HTTP handler or module to dynamically load a page - while allowing...
Filed under: , , ,
More Posts Next page »