Aug 21 2006

Page Properties and SqlDataSource-ObjectDataSource-AccessDataSource

Category: ASP.NET 2.0 - GeneralBil@l @ 13:57

A nice tip given by Stephan Walther in his latest book, ASP.NET 2.0 Unleashed is how to use a page property as a parameter to either Insert, Delete, Update, or Select parameters.

As you know, we have a set of new parameter objects that can be used to supply data to Sql, Object, and Access DataSources. Among which is the ControlParameter.

ControlParameter usually uses a control on the page. Since a Page is also a control, then we can use the Page control as follows

<asp:ControlParameter Name="IPAddress" ControlID="__page"
                PropertyName="IPAddress" />

In this example, you can see that the ControlParamter uses the ControlID as "__page", where __page is the name of the Page control at run time. The propertyName here represents a property that you have created on the page code-behind as:

    Public ReadOnly Property IPAddress() As String
            Return Request.UserHostAddress
        End Get
    End Property

So, you are able to use the Page property simply as input for the ControlParameter.

Hope this helps,



Comments are closed