Wrox Programmer Forums
Go Back   Wrox Programmer Forums > ASP.NET and ASP > ASP.NET 2.0 > ASP.NET 2.0 Professional
|
ASP.NET 2.0 Professional If you are an experienced ASP.NET programmer, this is the forum for your 2.0 questions. Please also see the Visual Web Developer 2005 forum.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the ASP.NET 2.0 Professional section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old March 17th, 2008, 10:35 AM
Friend of Wrox
 
Join Date: Oct 2003
Posts: 218
Thanks: 0
Thanked 0 Times in 0 Posts
Default Object Data Source class property

I am having difficulty assigning a property to be used in an ObjectDataSource SELECT method. I am able to set the parameters to match my method signature properly with no problem.

However, my method also uses an object public property - it is not part of the method signature. How am I able to set this public property and have it consumed by the method call?

It's like this:

Public Class myClass

Public Property myProp() As String
   Get
       Return m_myProp
   End Get
   Set(ByVal Value As String)
       m_myProp = Value
   End Set
End Property

Public Function GetData(myParam1 as Integer, myParam2 as String) as DataSet
    dim ds as DataSet
    .
    .
    If m_myProp = 1 Then
        'do something
    End If
    .
    return ds
End Function

Is my only option to change the method signature?

Thanks in advance for your comments.
 
Old March 17th, 2008, 11:49 AM
Imar's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
Default

Hi there,

Take a look here: http://imar.spaanjaars.com/QuickDocId.aspx?quickdoc=368 and look at method #3 in particular. It shows you how to create a new instance of your business object, set the necessary properties and then let the ODS figure out the rest.

Hope this helps,

Imar
---------------------------------------
Imar Spaanjaars
http://Imar.Spaanjaars.Com
Everyone is unique, except for me.
Author of Beginning ASP.NET 3.5 : in C# and VB, ASP.NET 2.0 Instant Results and Dreamweaver MX 2004
Want to be my colleague? Then check out this post.
 
Old March 17th, 2008, 11:56 AM
Friend of Wrox
 
Join Date: Oct 2003
Posts: 218
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Imar-

Funny you mention that. I took a look at it before I posted. I'm still not sure how you tie that OnCreated method to the method call.
 
Old March 17th, 2008, 12:05 PM
Imar's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
Default

First you need to write code for the ObjectCreating event of the ODS, like this:
Code:
Protected Sub ObjectDataSource1_ObjectCreating(ByVal sender As Object, _
       ByVal e As System.Web.UI.WebControls.ObjectDataSourceEventArgs) _
       Handles ObjectDataSource1.ObjectCreating
  Dim myInstance As New MyClass()
  myInstance.myProp = "Whatever value you need here"
  e.ObjectInstance = myInstance
End Sub
That way, an instance of your business object is created when the ODS is about to call your method.

Next, within your method, you should be able to retrieve the myProp property (using m_myprop or myProp) and get at the value you set in the ObjectCreating event in the page.

Hope this helps,

Imar
---------------------------------------
Imar Spaanjaars
http://Imar.Spaanjaars.Com
Everyone is unique, except for me.
Author of Beginning ASP.NET 3.5 : in C# and VB, ASP.NET 2.0 Instant Results and Dreamweaver MX 2004
Want to be my colleague? Then check out this post.
 
Old March 17th, 2008, 02:02 PM
Friend of Wrox
 
Join Date: Oct 2003
Posts: 218
Thanks: 0
Thanked 0 Times in 0 Posts
Default

That did the trick. I can now send my value to the object method.

Dank U Imar
 
Old March 17th, 2008, 03:21 PM
Imar's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
Default

Graag gedaan... ;)

Imar
---------------------------------------
Imar Spaanjaars
http://Imar.Spaanjaars.Com
Everyone is unique, except for me.
Author of Beginning ASP.NET 3.5 : in C# and VB, ASP.NET 2.0 Instant Results and Dreamweaver MX 2004
Want to be my colleague? Then check out this post.





Similar Threads
Thread Thread Starter Forum Replies Last Post
Object Data Source parameters nabeelalkaff BOOK: ASP.NET 2.0 Website Programming Problem Design Solution ISBN: 978-0-7645-8464-0 8 December 10th, 2007 12:34 AM
Object Data Source error shoakat ASP.NET 2.0 Professional 1 June 20th, 2007 05:40 PM
Object Data Source Error abupapa ASP.NET 2.0 Basics 1 June 13th, 2007 05:43 AM
Property access from Class within Partial Class zoltac007 C# 2005 0 December 1st, 2006 01:01 AM
Get all property values of class rrhandle ASP.NET 1.0 and 1.1 Basics 1 January 12th, 2006 05:13 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.