Wrox Programmer Forums

Need to download code?

View our list of code downloads.

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
Password Reminder
Register
| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
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 tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old March 29th, 2012, 11:17 AM
Registered User
Points: 32, Level: 1
Points: 32, Level: 1 Points: 32, Level: 1 Points: 32, Level: 1
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
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..
Reply With Quote
  #2 (permalink)  
Old March 29th, 2012, 11:22 AM
Imar's Avatar
Wrox Author
Points: 72,073, Level: 100
Points: 72,073, Level: 100 Points: 72,073, Level: 100 Points: 72,073, Level: 100
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2003
Location: Utrecht, Netherlands.
Posts: 17,089
Thanks: 80
Thanked 1,587 Times in 1,563 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!
Reply With Quote
  #3 (permalink)  
Old March 29th, 2012, 11:35 AM
Registered User
Points: 32, Level: 1
Points: 32, Level: 1 Points: 32, Level: 1 Points: 32, Level: 1
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
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.
Reply With Quote
  #4 (permalink)  
Old March 29th, 2012, 11:38 AM
Imar's Avatar
Wrox Author
Points: 72,073, Level: 100
Points: 72,073, Level: 100 Points: 72,073, Level: 100 Points: 72,073, Level: 100
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2003
Location: Utrecht, Netherlands.
Posts: 17,089
Thanks: 80
Thanked 1,587 Times in 1,563 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!
Reply With Quote
  #5 (permalink)  
Old March 29th, 2012, 02:43 PM
Registered User
Points: 32, Level: 1
Points: 32, Level: 1 Points: 32, Level: 1 Points: 32, Level: 1
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
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.
Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


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



All times are GMT -4. The time now is 05:46 AM.


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