Wrox Programmer Forums

Need to download code?

View our list of code downloads.

| FAQ | Members List | 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 June 6th, 2008, 01:59 PM
Authorized User
 
Join Date: Apr 2008
Location: , , .
Posts: 26
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via Yahoo to AspNetGuy
Default Chapter 9 Page 304

I have a TextBox contained in a DetailsView which is itself contained in a Wizard.

When I attempt the exercise in Chapter 9 on page 304 I receive the error message:

error CS0103: The name 'MyTextBox' does not exist in the current context

This is generated because of the following line:

var myTextBox = document.getElementById('<%= MyTextBox.ClientID %>');

So I attempted to adjust it to my code by changing the line of code to :

var myTextBox = document.getElementById('<%= MyDetailsView.MyTextBox.ClientID %>');

I then received the following error message.

error CS1061: 'System.Web.UI.WebControls.DetailsView' does not contain a definition for 'MyTextBox' and no extension method 'MyTextBox' accepting a first argument of type 'System.Web.UI.WebControls.DetailsView' could be found (are you missing a using directive or an assembly reference?)


I now realize I was a bit naive as to what was really going on.

Will the solution involve FindControl("MyTextBox")?

How do I get the ID of a control in a TEMPLATE field as described above.

Thanks.




Reply With Quote
  #2 (permalink)  
Old June 6th, 2008, 02:12 PM
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,

Is this the exact code from the book? Or did you modify it yourself? In the latter case, can you post more code?

Usually, you call FindControl on the control that contains the TextBox; the DetailsView in your case.

HtH,

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.
Reply With Quote
  #3 (permalink)  
Old June 6th, 2008, 02:24 PM
Authorized User
 
Join Date: Apr 2008
Location: , , .
Posts: 26
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via Yahoo to AspNetGuy
Default

Imar,

Your code works fine. It was the challenge of modifying the code to work in my case that was the problem. I changed the code to use FindControl and it works great now. Here is the final version of the line of code that works.

    var myTextBox = document.getElementById('<%= MyDetailsView.FindControl("MyTextBox").ClientID %>');

Again this was a TextBox contained in a DetailsView named MyDetailsView.

All is well.

Cheers back at yah!!
:)

Reply With Quote
  #4 (permalink)  
Old January 11th, 2009, 11:59 AM
Authorized User
 
Join Date: Jan 2009
Location: Norway
Posts: 21
Thanks: 5
Thanked 0 Times in 0 Posts
Default

Hi,

I also have a problem with the exercise on page 304. That is, I don' t get the expected behaviour in step 7.

If I click the Send button when all text boxes are empty, i get a red dot warning me of missing name, e-mail, e-mail confirmation and comment. After I write something in those boxes and press send, the warning of missing phone numbers is fired.
Why don't i get this warning together with the others?

I have most probably made a silly mistake somewhere, and it's driving me crazy
The source code that I downloaded for the book, works perfectly fine.
Reply With Quote
  #5 (permalink)  
Old January 11th, 2009, 12:02 PM
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,

Did you hook up (and write code) for the client side validation using JavaScript?

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
  #6 (permalink)  
Old January 11th, 2009, 12:15 PM
Authorized User
 
Join Date: Jan 2009
Location: Norway
Posts: 21
Thanks: 5
Thanked 0 Times in 0 Posts
Default

Hi again Imar,

I wrote this javascript function:

Code:
<scripttype="text/javascript">
function ValidatePhoneNumbers(source, args) 
{
var txtPhoneHome = document.getElementById('<%= txtPhoneHome.ClientID %>');
var txtPhoneBusiness = document.getElementById('<%= txtPhoneBusiness.ClientID %>');
if (txtPhoneHome.value != '' || txtPhoneBusiness.value != '')
{
args.isValid = true;
}
else
{
args.isValid = false;
}
}
</script>
After too many attempts to make my version of the customvalidator work, I copied your version(I put it in the same cell as the text box on purpose):

Code:
<tr>
<tdclass="style16">
Home phone number</td>
<tdclass="style21">
<asp:TextBoxID="txtPhoneHome"runat="server"></asp:TextBox>
<asp:CustomValidatorID="CustomValidator1"runat="server"ClientValidationFunction="ValidatePhoneNumbers"Display="Dynamic"ErrorMessage="Please enter your home or business phone number"onservervalidate="CustomValidator1_ServerValidate">*</asp:CustomValidator>
</td>
<tdclass="style16">
&nbsp;</td>
</tr>


Do you need to see more of my code to be able to solve this?
I have a strong feeling that I have done something "clever", which causes this problem. But I can't figure out what...
Since your code works, it can't be something with the configuration of my browser? Which is IE7.

Thanks again for answering my questions on a sunday!

..Håvard..
Reply With Quote
  #7 (permalink)  
Old January 11th, 2009, 12:18 PM
Authorized User
 
Join Date: Jan 2009
Location: Norway
Posts: 21
Thanks: 5
Thanked 0 Times in 0 Posts
Default

just a quick comment:

There is a space in my code, between "script" and "Type":
<script type="text/javascript">

It "disappeared" in my previous post...
Reply With Quote
  #8 (permalink)  
Old January 11th, 2009, 12:18 PM
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

Indeed, as my code seems to work, it must be something with your code.....

Have you considered comparing the two files and see where they differ? Do you have a tool to compare two files?

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
  #9 (permalink)  
Old January 11th, 2009, 12:43 PM
Authorized User
 
Join Date: Jan 2009
Location: Norway
Posts: 21
Thanks: 5
Thanked 0 Times in 0 Posts
Default

Hi,

I downloaded ExamDiff, which was the first free tool when I searched for "compare text files" on google.

It pointed out several differences between my and you version of the files, the ones that I think did the trick was to change "args.isValid" into "args.IsValid"

I wonder why Intellisense didn't work for these two lines inside that JavaScript function.

Anyway, problem is now solved. Thanks for point me in the right direction!

..Håvard...
Reply With Quote
  #10 (permalink)  
Old January 11th, 2009, 12:57 PM
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

IntelliSense can't help you as it doesn't know what args is. JavaScript isn't strongly typed as C# or VB.NET are so args doesn't have a value (and an IsValid property) until run-time.

Anyway, glad it's working now...

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
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 3 Page 95 jumpot89 BOOK: Beginning PHP5, Apache, and MySQL Web Development ISBN: 978-0-7645-7966-0 6 April 22nd, 2009 03:11 AM
Chapter 9, page 304 Again AspNetGuy BOOK: Beginning ASP.NET 3.5 : in C# and VB BOOK ISBN: 978-0-470-18759-3 3 June 15th, 2008 02:57 PM
Chapter 9 JavaScript Warning Message Page 304 workib BOOK: Beginning ASP.NET 3.5 : in C# and VB BOOK ISBN: 978-0-470-18759-3 5 May 28th, 2008 04:42 PM
Chapter 7 page 212 tgregory BOOK: Beginning ASP.NET 2.0 BOOK VB ISBN: 978-0-7645-8850-1; C# ISBN: 978-0-470-04258-8 4 May 3rd, 2007 01:44 PM
Chapter 7 Try It Out page 218 drumdiva BOOK: Beginning Visual Basic 2005 ISBN: 978-0-7645-7401-6 3 March 19th, 2007 08:35 PM



All times are GMT -4. The time now is 10:52 AM.


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