Wrox Programmer Forums
Go Back   Wrox Programmer Forums > ASP.NET and ASP > ASP.NET 3.5 > BOOK: Beginning ASP.NET 3.5 : in C# and VB BOOK ISBN: 978-0-470-18759-3
|
BOOK: Beginning ASP.NET 3.5 : in C# and VB BOOK ISBN: 978-0-470-18759-3
This is the forum to discuss the Wrox book Beginning ASP.NET 3.5: In C# and VB by Imar Spaanjaars; ISBN: 9780470187593
Welcome to the p2p.wrox.com Forums.

You are currently viewing the BOOK: Beginning ASP.NET 3.5 : in C# and VB BOOK ISBN: 978-0-470-18759-3 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 January 27th, 2010, 10:53 AM
Authorized User
 
Join Date: Apr 2009
Posts: 48
Thanks: 16
Thanked 0 Times in 0 Posts
Default Difference between LinqDataSource_inserting and DetailsView_ItemInserting?

Hello Imar,

Could you explain why in AddEditReviews you use

Code:
protected void DetailsView1_ItemInserting(object sender, DetailsViewInsertEventArgs e)
    {
        e.Values["UpdateDateTime"] = DateTime.Now;
    }
and in NewPhotoAlbum you use

Code:
protected void LinqDataSource1_Inserting(object sender, LinqDataSourceInsertEventArgs e)
    {
        PhotoAlbum myPhotoAlbum = (PhotoAlbum)e.NewObject;
        myPhotoAlbum.UserName = User.Identity.Name;
    }
couldn't you in the last case just as well have used

Code:
protected void DetailsView1_ItemInserting(object sender, DetailsViewInsertEventArgs e)
    {
        e.Values["UserName"] = User.Identity.Name;
    }
The thing is that I am a bit confused when to use which eventhandler.

Here in both cases the LinqDs is connected to a DetailsView, and I noticed that in ManagePhotoAlbum, that you prefer to use LinqDataSource_inserting for inserting the imageUrl.

So what's the rule here?

Best regards, Robin
 
Old January 27th, 2010, 11:42 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 Robin,

Yes, that would certainly work as well.

Personally, I prefer LinqDataSource1_Inserting over DetailsView1_Inserting as I get strongly typed access to my object. The DetailsView doesn't support it, so you need to use string literals which can easily break things. For example, what if you accidentally typed:

Code:
e.Values["UsrName"] = User.Identity.Name;
Or what if you renamed the UserName property to just User? With a string literal you wouldn't notice it until run-time. By accessing a strongly typed property of PhotoAlbum you can catch these kind of errors at development time.

In AddEditReview.aspx you can't do this and need to use the DetailsView1_Inserting as that pages uses a (weakly typed) SqlDataSource.

Hope this clarifies things a bit.

Cheers,

Imar
---------------------------------------------------------------------------------------------------------------------
Imar Spaanjaars
Web: Imar.Spaanjaars.Com Twitter: ImarSpaanjaars

Author of Beginning ASP.NET 4 : in C# and VB | Beginning ASP.NET 3.5 : in C# and VB | ASP.NET 2.0 Instant Results.
While typing this post, I was listening to: Loose Fit by Happy Mondays (Track 5 from the album: Pills 'N' Thrills And Bellyaches) What's This?
The Following User Says Thank You to Imar For This Useful Post:
robbaralla (January 27th, 2010)
 
Old January 27th, 2010, 12:02 PM
Authorized User
 
Join Date: Jan 2010
Posts: 34
Thanks: 5
Thanked 0 Times in 0 Posts
Default follow up question

hi
is it right to say that when using Linq we can use the LinqDataSource1_Inserting or other events since we have stronly typed access
and when using sqldatasource we better use the data bounding object (i.e. gridview, detailsview etc...) ing functions (i.e. inserting,updating ,deleteing)
and use
Quote:
e.Values["UpdateDateTime"] =someValue
or we can use this syntax in the sqldatasource "ing" functions as well:
Quote:
Protected Sub SqlDataSource1_Inserting(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.SqlDataSourceCommandEven tArgs) Handles SqlDataSource1.Inserting
'do soething with e
'like e.Command.Parameters("somefield") or something?
End Sub
thanks
Barak
 
Old January 27th, 2010, 12:08 PM
Imar's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
Default

Yes, that's correct. And yes, you could use the Inserting event of the SqlDataSource using something like this:

Code:
e.Command.Parameters["@UpdateDateTime"].Value = DateTime.Now;
Personally, I find indexing the Parameters collection and using the @ symbol a bit verbose and prefer the simpler

Code:
 e.NewValues["UpdateDateTime"] = DateTime.Now;
instead, but I guess that's a matter of personal taste...

Imar
---------------------------------------------------------------------------------------------------------------------
Imar Spaanjaars
Web: Imar.Spaanjaars.Com Twitter: ImarSpaanjaars

Author of Beginning ASP.NET 4 : in C# and VB | Beginning ASP.NET 3.5 : in C# and VB | ASP.NET 2.0 Instant Results.
While typing this post, I was listening to: Michael by Franz Ferdinand (Track 9 from the album: Franz Ferdinand) What's This?





Similar Threads
Thread Thread Starter Forum Replies Last Post
Difference between name(*) and name() vikkiefd XSLT 3 March 11th, 2008 06:40 AM
difference Magen Classic ASP Basics 2 January 29th, 2007 04:48 PM
what's the difference? jdkxxx Oracle 3 October 8th, 2005 12:33 PM
what is the difference? chuck_schuldiner Javascript How-To 2 February 10th, 2005 01:46 AM
what is the difference between... chuck_schuldiner Javascript 2 February 10th, 2005 01:41 AM





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