 |
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
|
|
|
|
|

June 6th, 2008, 01:59 PM
|
|
Authorized User
|
|
Join Date: Apr 2008
Posts: 26
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
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.
|
|

June 6th, 2008, 02:12 PM
|
 |
Wrox Author
|
|
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
|
|
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.
|
|

June 6th, 2008, 02:24 PM
|
|
Authorized User
|
|
Join Date: Apr 2008
Posts: 26
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
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!!
:)
|
|

January 11th, 2009, 11:59 AM
|
|
Authorized User
|
|
Join Date: Jan 2009
Posts: 21
Thanks: 5
Thanked 0 Times in 0 Posts
|
|
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.
|
|

January 11th, 2009, 12:02 PM
|
 |
Wrox Author
|
|
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
|
|
Hi there,
Did you hook up (and write code) for the client side validation using JavaScript?
Imar
|
|

January 11th, 2009, 12:15 PM
|
|
Authorized User
|
|
Join Date: Jan 2009
Posts: 21
Thanks: 5
Thanked 0 Times in 0 Posts
|
|
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">
</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..
|
|

January 11th, 2009, 12:18 PM
|
|
Authorized User
|
|
Join Date: Jan 2009
Posts: 21
Thanks: 5
Thanked 0 Times in 0 Posts
|
|
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...
|
|

January 11th, 2009, 12:18 PM
|
 |
Wrox Author
|
|
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
|
|
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
|
|

January 11th, 2009, 12:43 PM
|
|
Authorized User
|
|
Join Date: Jan 2009
Posts: 21
Thanks: 5
Thanked 0 Times in 0 Posts
|
|
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...
|
|

January 11th, 2009, 12:57 PM
|
 |
Wrox Author
|
|
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
|
|
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
|
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 |
|
 |