Contents tagged with code
-
HttpRequest Using IsAjax & IsJson Extension Methods
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 request is AJAX or JSON?
-
How To: Access Underlying Data of the ObjectDataSource
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:
-
Revision: Get the Value of a Control Without an Instance of the Control
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:
-
Revision: Case-Insensitive String Equality
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:
-
To Compile or Not Compile
ASP.NET 2.0 allows developers to configure whether a page compiles or not. Consider the following page directive:
-
How To: Create a Strongly-Typed Property For HttpContext.Items
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, the key/value pair is not strongly-typed. If I am going to access a value often, I would like to make the call as simple as possible. Here is an example of a property I created that "wraps" HttpContext.Items around a key value, yet exposing the value as a string, not object:
-
How To: "Upsert" Into AppSettings
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 file directly.
-
How To: Obtain Method Name Programmatically For Tracing
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:
-
How To: Return Embedded Resource Content As String
Here is a utility method for returning any embedded resource content as a string:
-
How To: Dynamically Load A Page For Processing
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 me to programmatically change key properties before processing. Here is a method that accomplishes such a task: