Wrox Programmer Forums
|
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 March 29th, 2012, 11:17 AM
Registered User
 
Join Date: Mar 2012
Posts: 6
Thanks: 1
Thanked 0 Times in 0 Posts
Default Chapter 16, Page 579, Get “User.Identity.Name”

Hello,

I worked through the chapter 16, page 578 Try It Out. Everything worked fine.

However, I want to use SQLDataSource, not LinqDataSource. If I change to SqlDataSource, I cannot get myPhotoAlbum.UserName which set up as User.Identity.Name.

Would you please help me and let me know how to get “User.Identity.Name when use SqlDataSource?

Thanks a lot.

The NewPhotoAlbum.asps.vb is as below:

Code:
 
Partial Class NewPhotoAlbum
    Inherits BasePage

   

    Protected Sub SqlDataSource1_Inserting(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.SqlDataSourceCommandEventArgs) Handles SqlDataSource1.Inserting

        Dim myPhotoAlbum As PhotoAlbum = CType(e.NewObject, PhotoAlbum)
        myPhotoAlbum.UserName = User.Identity.Name

    End Sub
End Class
The error message is as below:

Compilation Error
Description: An error occurred during the compilation of a resource required to service this request. Please review the following specific error details and modify your source code appropriately.

Compiler Error Message: BC30456: 'NewObject' is not a member of 'System.Web.UI.WebControls.SqlDataSourceCommandEve ntArgs'.

Source Error:


Line 9:
Line 10: Protected Sub SqlDataSource1_Inserting(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.SqlDataSourceCommandEven tArgs) Handles SqlDataSource1.Inserting
Line 11: Dim myPhotoAlbum As PhotoAlbum = CType(e.NewObject, PhotoAlbum)
Line 12: myPhotoAlbum.UserName = User.Identity.Name
Line 13:

Source File: C:\AttendanceDatebase\Site\NewPhotoAlbum.aspx.vb Line: 11

Last edited by jjjane; March 29th, 2012 at 11:19 AM..
 
Old March 29th, 2012, 11:22 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 at Chapter 12, Page 409 and fiurther. The examples show you how to access the e.Values property inside the Inserting event of the data control (e.g. a DetailsView for example).

An SqlDataSource control is not strongly typed and thus doesn't provide access to something like the UserName property.

What's the reason you don't want to use a LinqDataSource?

Cheers,

Imar
__________________
Imar Spaanjaars
http://Imar.Spaanjaars.Com
Follow me on Twitter

Author of Beginning ASP.NET 4.5 : in C# and VB, Beginning ASP.NET Web Pages with WebMatrix
and Beginning ASP.NET 4 : in C# and VB.
Did this post help you? Click the button below this post to show your appreciation!
 
Old March 29th, 2012, 11:35 AM
Registered User
 
Join Date: Mar 2012
Posts: 6
Thanks: 1
Thanked 0 Times in 0 Posts
Default UserName

Hi, Imar,

I am surprised that you answer my question so quick. Thanks you so much.

I feel I am more comfortable with SQL data source. Can I create the Try IT Out at Chaper 12, Page 410 for “AddEditReview.aspx” with LinqDataSource?

If I can, I do want to try to use LinqDataSource.


Thanks again.
 
Old March 29th, 2012, 11:38 AM
Imar's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
Default

Yes you can; most of the concepts are the same, although the implementation will be slightly different. I'd say: give it a try, and post follow up messages with relevant source code here if you get stuck.

You'll find lots of useful examples in the chapter on LINQ.

Cheers,

Imar
__________________
Imar Spaanjaars
http://Imar.Spaanjaars.Com
Follow me on Twitter

Author of Beginning ASP.NET 4.5 : in C# and VB, Beginning ASP.NET Web Pages with WebMatrix
and Beginning ASP.NET 4 : in C# and VB.
Did this post help you? Click the button below this post to show your appreciation!
 
Old March 29th, 2012, 02:43 PM
Registered User
 
Join Date: Mar 2012
Posts: 6
Thanks: 1
Thanked 0 Times in 0 Posts
Thumbs up Thanks, Imar.

Imar,

Thanks you so much!

I used e.values, and got user name.





Similar Threads
Thread Thread Starter Forum Replies Last Post
Chapter 16, Page 584 JHubschman BOOK: Beginning ASP.NET 4 : in C# and VB 5 August 26th, 2011 05:56 PM
Chapter 16 Page 558 runner1181 BOOK: Beginning ASP.NET 3.5 : in C# and VB BOOK ISBN: 978-0-470-18759-3 1 February 9th, 2010 03:18 AM
Chapter 15, POSTing a SOAP message ;example on 579 kbrown BOOK: Beginning XML 3rd Edition 3 August 25th, 2006 05:23 PM
Chapter 1 Page 16 - Try It Out bradnerdhss BOOK: Beginning ASP.NET 2.0 BOOK VB ISBN: 978-0-7645-8850-1; C# ISBN: 978-0-470-04258-8 1 January 31st, 2006 02:11 PM





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