 |
BOOK: Beginning ASP.NET 4 : in C# and VB
 | This is the forum to discuss the Wrox book Beginning ASP.NET 4: in C# and VB by Imar Spaanjaars; ISBN: 9780470502211 |
Welcome to the p2p.wrox.com Forums.
You are currently viewing the BOOK: Beginning ASP.NET 4 : in C# and VB 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
|
|
|
|
|

September 26th, 2012, 11:15 AM
|
|
Registered User
|
|
Join Date: Sep 2012
Posts: 8
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
DateTime code
Hi all
I am reading the following BOOK: Beginning ASP.NET 3.5 : in C# and VB chapter 1 and I hope that you can help me please with this code
<div>
<h1>Hello World</h1>
<p>Welcome to Beginning ASP.NET 3.5 on <% = DateTime.Now.toString %> </p>
</div>
As far as I understood it
this a heading 1 with the <h1> </h1> tag
the paragraph indicated by <p> </p> tag
the <% = DateTime.Now.toString %> the word now used to insert the current date and time but why do we need to put toString ??
have I missed something with my code on line //3 can anybody explain please as I am now to this.
With many thanks
Kind regards
Zulu2012
|
|

September 26th, 2012, 11:33 AM
|
 |
Wrox Author
|
|
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
|
|
Hi there,
Quote:
|
have I missed something with my code on line //3 can anybody explain please as I am now to this.
|
Hard to say without more information. Is it not working? If it isn't, do you get an error? Which language do you use? VB or C#? C# is case sensitive and requires parentheses, so you would need to write ToString() instead of toString.
Quote:
but why do we need to put toString ??
|
<%= %> is a shortcut for Response.Write. The Write method accepts a string only. DateTime.Now on the other hand is a DateTime which is not directly compatible with a string. By calling ToString on the DateTime you can retrieve its string representation.
In this case, it would also work without the call to ToString. However, as you'll see in later chapters, this conversion is required in other places.
Cheers,
Imar
|
|

September 26th, 2012, 11:58 AM
|
|
Registered User
|
|
Join Date: Sep 2012
Posts: 8
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Reply dateTime code
Reply hello again
Thank you very much for your reply I think that I am using C# in VWD and from what I can say that the date and time is a number and string is a text yes I missed the two closing brackets () after the ToString but I am sorry to say that I still have some errors I copied them below, can you please advise of what is my mistake with many thanks for all your help. With kind regards Zulu2012
Parser Error
Description: An error occurred during the parsing of a resource required to service this request. Please review the following specific parse error details and modify your source file appropriately.
Parser Error Message: Only Content controls are allowed directly in a content page that contains Content controls.
Source Error:
Line 17: </asp:Content>
Line 18:
Line 19: <div>
Line 20: <h1>Hello World</h1>
Line 21: <p>Welcome to Beginning ASP.NET 3.5 on <% = DateTime.Now.ToString(); %> </p>
Source File: /WebSite2/Default.aspx Line: 19
________________________________________
Version Information: Microsoft .NET Framework Version:4.0.30319; ASP.NET Version:4.0.30319.17929
|
|

September 26th, 2012, 12:19 PM
|
 |
Wrox Author
|
|
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
|
|
Hi there,
A few things. First, as the error message suggest, you seem to have your content outside the <content> control which is not allowed:
Code:
Line 17: </asp:Content>
Line 18:
Line 19: <div>
Line 20: <h1>Hello World</h1>
Line 21: <p>Welcome to Beginning ASP.NET 3.5 on <% = DateTime.Now.ToString(); %> </p>
Secondly, you can't have a semi-colon after ToString; it's not a statement; it's a value you're sending to Response.Write.
Thirdly, take a look at the source code that comes with the book (downloadable from this website) so you can compare your code with mine.
Finally, you said you have the 3.5 version of the book, but you posted in the 4.0 forum. To avoid future confusion, please post new questions in the appropriate forum at: http://p2p.wrox.com/book-beginning-a...0-18759-3-389/
Cheers,
Imar
|
|

September 27th, 2012, 12:51 PM
|
|
Registered User
|
|
Join Date: Sep 2012
Posts: 8
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
DateTime code
Dear Imar
Thank you very much for your reply, I am sorry to post my question in the wrong form yes I am reading your book Beginning ASP.NET 3.5: In C# and VB kindle edition because I am short sighted and I am struggling to see your code in the book I tried the downloadable code to compare your code with mine but I can start viewing the code from chapter 2 as there is no code for chapter 1, would you advise me to leave my book and start reading your new book Beginning ASP.NET 4: In C# and VB or is the 3.5 version still ok as my visual studio is version 4,
With many thanks
Zulu2012
|
|

September 28th, 2012, 09:39 AM
|
 |
Wrox Author
|
|
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
|
|
Ah, yes, you're right. There is no code for Chapter 1. Sorry about that.
You could use the 3.5 version with VS 2010, but you'll run into some troubles with the ASP.NET controls such as Menu as they render differently in .NET 4. As such, the CSS that comes with the 3.5 book doesn't work correctly with the 4.0 version. You could downgrade your site to ASP.NET 3.5 (on the Property Pages for the site) or you could use the 4.0 code that you can download from this site.
Alternatively, you could wait for my ASP.NET 4.5 book to be released (real soon) and install a copy of the free Visual Studio Express 2012 for Web that the book uses.
Cheers,
Imar
|
|

October 1st, 2012, 11:29 AM
|
|
Registered User
|
|
Join Date: Sep 2012
Posts: 8
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Reply dateTime code
Dear Imar
Thank you for your reply, I am glad that you informed me that there is no code for chapter 1, I understand what you mean, so I can download the code for ASP.NET 4.0 and still uses the ASP.NET 3.5 book but use the downloaded code for your ASP.NET 4.0 book to go with it. I am running visual studio express 2010 version 4.5 and I am happy to wait for your new book release ASP.NET 4.5 I will be grateful if you can advise what date that your new book will be available so I will buy a copy and download the code with visual Studio 2012.
Thank you I am looking forward to hear from you and looking forward to get your new ASP.NET 4.5 book.
Kind regards
Zulu2012
|
|

October 1st, 2012, 11:42 AM
|
 |
Wrox Author
|
|
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
|
|
It goes to the printer tomorrow ;-) Amazon.com says it's available on November 6th.
Imar
|
|

October 1st, 2012, 11:46 AM
|
|
Authorized User
|
|
Join Date: Mar 2012
Posts: 59
Thanks: 2
Thanked 4 Times in 4 Posts
|
|
Well done Imar and Good Luck on the New Book.
Ian
|
|

October 3rd, 2012, 10:28 AM
|
|
Registered User
|
|
Join Date: Sep 2012
Posts: 8
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
new book
Dear Imar
Thank you for your reply and well done with your new book, yes I have check on amazon uk and the paperback version will be available on 9 Nov, however I prefer to buy the kindle format can you please advise if I will be able to get the book in kindle format or PDF format?.
In the mean time I downloaded the code for book 4 and I will carry on reading my 3.5 book and using your code for book 4. Is that ok?
Thank you
Kind regards
Zulu2012
|
|
 |
|